示例#1
0
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"]
示例#2
0
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={})
    ]
示例#3
0
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,
    )]
示例#4
0
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={})
    }
示例#5
0
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",
    ]
示例#6
0
def test_schedule_decorator(deferrer, task):
    deferrer.periodic_decorator(cron="0 0 * * *")(task)

    assert deferrer.periodic_tasks == [
        periodic.PeriodicTask(task=task, cron="0 0 * * *")
    ]
示例#7
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 * * *")
    ]