aio_task package

Submodules

aio_task.broker module

Broker produce tasks that will be processed by consumers.

class aio_task.broker.Broker[source]

Bases: object

Task getter and producer.

async close()[source]

Shutdown.

classmethod create(queue_type, queue_conf, cache_type, cache_conf)[source]

Create a new broker instance.

async create_task(task_name, params=None)[source]

Create a new task.

Parameters
  • task_name (str) –

  • params (dict) –

Returns

A task_id

Return type

str

Raises

ValueError is task_name is not referencing any task.

async get_task(task_id)[source]

Fetch a task

:param task :rtype: Task :raises: ValueError is task_id is not referencing any task.

aio_task.task module

Define Task interface.

class aio_task.task.Task(task_id, name, params, created_at, finished_at, result)[source]

Bases: object

Task is produced by brokers and refer to an handler registed by a consumer.

If an exception occure during the task processing, task result is set to {“exception”: str(exception)}

property done

Bool - task is over.

dump()[source]

Serialization.

classmethod load(dump)[source]

Load Task from a dump.

classmethod new(name, params)[source]

Get a task instance.

set_result(result)[source]

Set a result to a task.

Parameters

result – json serializable.

Raises

aio_task.utils module

Broker produce tasks that will be processed by consumers.

aio_task.utils.load_cache(cache_type)[source]
aio_task.utils.load_consumer(queue_type)[source]
aio_task.utils.load_producer(queue_type)[source]

aio_task.worker module

Register handlers to process tasks produced by the broker.

class aio_task.worker.Worker[source]

Bases: object

Worker register handlers and consume tasks.

async close()[source]

Shutdown.

classmethod create(queue_type, queue_conf, cache_type, cache_conf)[source]

Create a new consumer instance.

async on_message(message)[source]

Receiv a new message from the broker.

register_handler(coro, task_name=None)[source]

Register a handler that process a task.

Parameters
  • coro – coroutine

  • task_name (str) – The name under which register the task. Default the use the coro.__name__

Raises

ValueError: handler was already registred for the task

async start()[source]

Start to consumer tasks from the queue.