Skip to content

celery

This module is concerned with defining the Celery client that is used to send tasks to the broker queue.

get_celery_client

get_celery_client(host: str = 'rabbitmq') -> Generator[Celery, None, None]

get_celery_client creates a celery app that will be used to connect to the task queue

Parameters:

Name Type Description Default
host str

host of the rabbitmq broker used for the celery task queue, by default "rabbitmq"

'rabbitmq'

Yields:

Type Description
Celery

celery app used to send tasks to the celery task queue

Source code in api/core/celery.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def get_celery_client(host: str = "rabbitmq") -> Generator[Celery, None, None]:
    """
    get_celery_client creates a celery app that will be used to connect to the task queue

    Parameters
    ----------
    host : str, optional
        host of the rabbitmq broker used for the celery task queue, by default "rabbitmq"

    Yields
    ------
    Celery
        celery app used to send tasks to the celery task queue
    """
    client = Celery(
        "tasks", broker=f"amqp://{settings.default_user}:{settings.default_pass}@{host}:5672/", backend="rpc://"
    )
    yield client
    client.close()