示例#1
0
async def test_standard_scheduler_stop() -> None:
    scheduler = StandardScheduler()
    trigger_1 = Trigger(id='001', process_id='001', pattern='*!1 * * * *')
    trigger_2 = Trigger(id='002', process_id='002', pattern='*!2 * * * *')

    calls = []

    async def mock_callable(triggers: List[Trigger]) -> None:
        nonlocal calls
        calls.extend(triggers)

    await scheduler.schedule([trigger_1, trigger_2])
    await scheduler.subscribe(mock_callable)
    await scheduler.start()

    await sleep(1)

    await scheduler.stop()
    await scheduler.stop()  # check idempotency

    await sleep(1)

    assert len(calls) <= 2
    assert calls.count(trigger_1) == 1
    assert calls.count(trigger_2) <= 1
示例#2
0
async def test_standard_scheduler_schedule() -> None:
    triggers = [
        Trigger(id='001', process_id='001'),
        Trigger(id='002', process_id='002')
    ]

    scheduler = StandardScheduler()
    await scheduler.schedule(triggers)

    assert scheduler.triggers == set(triggers)
示例#3
0
def trigger_repository(tenant_provider, auth_provider):
    trigger_repository = MemoryTriggerRepository(QueryParser(),
                                                 tenant_provider,
                                                 auth_provider)
    trigger_repository.load({
        'default': {
            '001': Trigger(id='001', process_id='002'),
            '002': Trigger(id='002', process_id='001')
        }
    })
    return trigger_repository
示例#4
0
def test_trigger_instantiation():
    trigger = Trigger(id='001', process_id='001')

    assert trigger.id == '001'
    assert trigger.type == 'cron'
    assert trigger.pattern == '* * * * *'
    assert trigger.process_id == '001'
示例#5
0
async def test_standard_scheduler_notify() -> None:
    scheduler = StandardScheduler()
    trigger_1 = Trigger(id='001', process_id='001', pattern='* * * * *')

    calls = []

    async def mock_callable(triggers: List[Trigger]) -> None:
        nonlocal calls
        calls.extend(triggers)

    now = datetime.now(timezone.utc)

    await scheduler._notify(now)

    assert len(calls) == 0

    await scheduler.subscribe(mock_callable)

    await scheduler._notify(now)

    assert len(calls) == 0

    await scheduler.schedule([trigger_1])

    await scheduler._notify(now)

    assert len(calls) == 1
示例#6
0
async def test_launch_coordinator_launch(launch_coordinator):
    triggers = [Trigger(id='001', process_id='002')]

    await launch_coordinator.launch(triggers)

    processes = launch_coordinator.executor.executed
    assert len(processes) == 1
    assert processes[0].id == '002'
def trigger_repository(tenant_provider, auth_provider, parser):
    trigger_repository = MemoryTriggerRepository(parser, tenant_provider,
                                                 auth_provider)
    trigger_repository.load(
        {'default': {
            '001': Trigger(**{
                'id': '001',
                'process_id': '001'
            })
        }})
    return trigger_repository