async def test_defer_jobs_already(periodic_deferrer, task, connector, caplog): caplog.set_level("DEBUG") connector.periodic_defers[(task.name, "foo")] = 1 pt = periodic.PeriodicTask(task=task, cron="* * * * *", periodic_id="foo", configure_kwargs={}) await periodic_deferrer.defer_jobs([(pt, 1)]) assert connector.queries == [( "defer_periodic_job", { "queue": "default", "args": { "timestamp": 1 }, "defer_timestamp": 1, "lock": None, "queueing_lock": None, "task_name": task.name, "periodic_id": "foo", }, )] assert [r.action for r in caplog.records] == ["periodic_task_already_deferred"]
def test_schedule_decorator(periodic_deferrer, task): periodic_deferrer.periodic_decorator(cron="0 0 * * *", periodic_id="foo")(task) assert list(periodic_deferrer.periodic_tasks.values()) == [ periodic.PeriodicTask(task=task, cron="0 0 * * *", periodic_id="foo", configure_kwargs={}) ]
def test_get_previous_tasks(periodic_deferrer, cron_task, task): cron_task(cron="* * * * *") assert list(periodic_deferrer.get_previous_tasks(at=3600 * 24 - 1)) == [( periodic.PeriodicTask(task=task, cron="* * * * *", periodic_id="", configure_kwargs={}), 3600 * 24 - 60, )]
def test_register_task(periodic_deferrer, task): periodic_deferrer.register_task(task=task, cron="0 0 * * *", periodic_id="foo", configure_kwargs={}) assert periodic_deferrer.periodic_tasks == { (task.name, "foo"): periodic.PeriodicTask(task=task, cron="0 0 * * *", periodic_id="foo", configure_kwargs={}) }
async def test_defer_jobs_queueing_lock(periodic_deferrer, task, caplog): caplog.set_level("DEBUG") pt1 = periodic.PeriodicTask( task=task, cron="* * * * *", periodic_id="foo", configure_kwargs={"queueing_lock": "bar"}, ) pt2 = periodic.PeriodicTask( task=task, cron="* * * * *", periodic_id="foo", configure_kwargs={"queueing_lock": "bar"}, ) caplog.clear() await periodic_deferrer.defer_jobs([(pt1, 1), (pt2, 2)]) assert [r.action for r in caplog.records] == [ "periodic_task_deferred", "skip_periodic_task_queueing_lock", ]
def test_schedule_decorator(deferrer, task): deferrer.periodic_decorator(cron="0 0 * * *")(task) assert deferrer.periodic_tasks == [ periodic.PeriodicTask(task=task, cron="0 0 * * *") ]
def test_register_task(deferrer, task): deferrer.register_task(task=task, cron="0 0 * * *") assert deferrer.periodic_tasks == [ periodic.PeriodicTask(task=task, cron="0 0 * * *") ]