# 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


def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)

    gengine.main({}, **settings)

    sess = DBSession()


    enginetasks = get_task_registry().registrations

    to_run = []

    with transaction.manager:
        mark_changed(sess, transaction.manager, True)

        tasks = sess.execute(
            select([
                m.t_tasks.c.entry_name,
                m.t_tasks.c.task_name,
                m.t_tasks.c.config,
                m.t_taskexecutions.c.id.label("execution_id"),
            ], from_obj=m.t_taskexecutions.join(m.t_tasks)).\
            where(and_(

# 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



def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)

    gengine.main({}, **settings)

    sess = DBSession()


    enginetasks = get_task_registry().registrations

    to_run = []

    with transaction.manager:
        mark_changed(sess, transaction.manager, True)

        tasks = sess.execute(
            select([
                m.t_tasks.c.entry_name,
                m.t_tasks.c.task_name,
                m.t_tasks.c.config,
                m.t_taskexecutions.c.id.label("execution_id"),
            ], from_obj=m.t_taskexecutions.join(m.t_tasks)).\
            where(and_(

                m.t_taskexecutions.c.planned_at < dt_now(),