Ejemplo n.º 1
0
 def listener(self):
     assert self.notify_event
     return utils.task_context(
         awaitable=self.job_store.listen_for_jobs(event=self.notify_event,
                                                  queues=self.queues),
         name="listener",
     )
Ejemplo n.º 2
0
async def test_task_context_exit_normally(caplog):
    done = []

    async def foo():
        done.append(True)

    with utils.task_context(foo(), name="foo"):
        await asyncio.sleep(0)

    assert done == [True]
Ejemplo n.º 3
0
async def test_task_context_exception(caplog):
    async def foo():
        0 / 0

    with utils.task_context(foo(), name="foo") as task:
        await asyncio.sleep(0)

    # Give the task a cycled to update
    await asyncio.sleep(0)
    assert task.done() is True

    exc_logs = [r for r in caplog.records if r.action == "foo_error" and r.exc_info]
    assert len(exc_logs) == 1
Ejemplo n.º 4
0
async def test_task_context_cancelled(caplog):
    done = []

    async def foo():
        done.append(True)
        await asyncio.sleep(10)

    caplog.set_level("DEBUG")

    with utils.task_context(foo(), name="foo") as task:
        await asyncio.sleep(0)

    assert done == [True]
    # Give the task a cycle to update
    await asyncio.sleep(0)
    assert task.cancelled() is True

    assert len([r for r in caplog.records if r.action == "foo_stop"]) == 1
Ejemplo n.º 5
0
 def periodic_deferrer(self):
     return utils.task_context(
         awaitable=self.app.periodic_deferrer.worker(),
         name="periodic_deferrer")