# Path: gengine/base/util.py
# def dt_now():
#     return datetime.datetime.utcnow().replace(tzinfo=pytz.utc)


import sys
import logging
import os
import transaction
    import gengine
    import gengine.app.model as m
from gengine.base.util import dt_now
from sqlalchemy.sql.expression import and_, select
from zope.sqlalchemy.datamanager import mark_changed
from pyramid.paster import (
    get_appsettings,
    setup_logging,
)
from pyramid.scripts.common import parse_vars
    from gengine.metadata import (
        DBSession
    )
    from gengine.app.registries import get_task_registry

                sess.execute(
                    m.t_taskexecutions.update().values({
                        'locked_at' : dt_now()
                    }).where(
                        m.t_taskexecutions.c.id == task["execution_id"]
                    )
                )

        sess.flush()
        sess.commit()

    for task in to_run:
        with transaction.manager:
            mark_changed(sess, transaction.manager, True)

            log.info("Running task %(task_name)s (ExecutionID: %(execution_id)s)" % {
                'task_name': task["task_name"],
                'execution_id': task["execution_id"]
            })

            result = get_task_registry().execute(
                name=task["task_name"],
                config=task["config"]  # execute contains fallback to default_config
            )
            logged = result.get("log", None)
            success = result.get("success", True)

            sess.execute(
                m.t_taskexecutions.update().values({

# Path: gengine/base/util.py
# def dt_now():
#     return datetime.datetime.utcnow().replace(tzinfo=pytz.utc)


# Path: gengine/maintenance/scripts/scheduler_worker.py
import sys
import logging
import os
import transaction
    import gengine
    import gengine.app.model as m
from gengine.base.util import dt_now
from sqlalchemy.sql.expression import and_, select
from zope.sqlalchemy.datamanager import mark_changed
from pyramid.paster import (
    get_appsettings,
    setup_logging,
)
from pyramid.scripts.common import parse_vars
    from gengine.metadata import (
        DBSession
    )
    from gengine.app.registries import get_task_registry


                sess.execute(
                    m.t_taskexecutions.update().values({
                        'locked_at' : dt_now()
                    }).where(
                        m.t_taskexecutions.c.id == task["execution_id"]
                    )
                )

        sess.flush()
        sess.commit()

    for task in to_run:
        with transaction.manager:
            mark_changed(sess, transaction.manager, True)

            log.info("Running task %(task_name)s (ExecutionID: %(execution_id)s)" % {
                'task_name': task["task_name"],
                'execution_id': task["execution_id"]
            })

            result = get_task_registry().execute(
                name=task["task_name"],
                config=task["config"]  # execute contains fallback to default_config
            )
            logged = result.get("log", None)
            success = result.get("success", True)

            sess.execute(
                m.t_taskexecutions.update().values({

                    'finished_at': dt_now(),