Exemplo n.º 1
0
def test_get_default_scheduler_with_some_os_env(mock_client):
    try:
        os.environ['CODEPACK_SCHEDULER_SOURCE'] = 'mongodb'
        os.environ['CODEPACK_SCHEDULER_DB'] = 'test_db'
        os.environ['CODEPACK_SCHEDULER_COLLECTION'] = 'test_collection'
        os.environ['CODEPACK_SCHEDULER_SUPERVISOR'] = 'dummy_supervisor'
        os.environ['CODEPACK_MONGODB_REPLICASET'] = 'TEST'
        scheduler = Default.get_scheduler()
        assert isinstance(scheduler, Scheduler)
        assert 'codepack' in scheduler.jobstores
        jobstore = scheduler.jobstores['codepack']
        assert hasattr(jobstore, 'storage')
        assert isinstance(jobstore.storage, MongoStorage)
        assert jobstore.storage.db == 'test_db'
        assert jobstore.storage.collection == 'test_collection'
        assert jobstore.storage.item_type == StorableJob
        assert jobstore.storage.key == 'id'
        assert scheduler.supervisor == 'dummy_supervisor'
        mock_client.assert_called_once_with(host='localhost',
                                            port=27017,
                                            replicaset='TEST')
    finally:
        os.environ.pop('CODEPACK_SCHEDULER_SOURCE', None)
        os.environ.pop('CODEPACK_SCHEDULER_DB', None)
        os.environ.pop('CODEPACK_SCHEDULER_COLLECTION', None)
        os.environ.pop('CODEPACK_SCHEDULER_SUPERVISOR', None)
        os.environ.pop('CODEPACK_MONGODB_REPLICASET', None)
Exemplo n.º 2
0
def test_get_default_scheduler():
    scheduler = Default.get_scheduler()
    assert isinstance(scheduler, Scheduler)
    assert 'codepack' in scheduler.jobstores
    jobstore = scheduler.jobstores['codepack']
    assert hasattr(jobstore, 'storage')
    assert isinstance(jobstore.storage, MemoryStorage)
    assert jobstore.storage.item_type == StorableJob
    assert jobstore.storage.key == 'id'
    assert scheduler.supervisor is None
Exemplo n.º 3
0
async def startup():
    Default.init()
    config = Default.config.get_config(section='apiserver')
    _scheduler = config.get('scheduler', 'self')
    common.add(key='supervisor', value=Default.get_employee('supervisor'), destroy=destroy_supervisor)
    if isinstance(_scheduler, Scheduler):
        common.add(key='scheduler', value=_scheduler, destroy=destroy_scheduler)
        common.scheduler.start()
    elif isinstance(_scheduler, str):
        if _scheduler == 'self':
            common.add(key='scheduler', value=Default.get_scheduler(), destroy=destroy_scheduler)
            common.scheduler.start()
        else:
            common.add(key='scheduler', value=_scheduler)
Exemplo n.º 4
0
async def startup():
    Default.init()
    common.add(key='scheduler',
               value=Default.get_scheduler(),
               destroy=destroy_scheduler)
    common.scheduler.start()