Skip to content

Controller

Controller

log module-attribute

log = getLogger(__name__)

Encapsulates the logic of the API for the worker router

add_queue_to_worker async

add_queue_to_worker(id: str, queue_name: str) -> None

Adds a queue to the worker specified by the id.

Parameters:

Name Type Description Default
id str

The id of the worker.

required
queue_name str

The name of the queue to be added.

required

Returns:

Type Description
None

None

check_worker_name

check_worker_name(name: str) -> bool

Check if the worker name is valid

Parameters:

Name Type Description Default
name str

The name of the worker.

required

Returns:

Name Type Description
bool bool

True if the worker name is not valid, otherwise False.

get_worker_jobqueues async

get_worker_jobqueues(name: str) -> list[GetWorkerJobqueue]

Get a list of all job queues for the worker specified by the id.

Parameters:

Name Type Description Default
name str

The id of the worker.

required

Returns:

Type Description
list[GetWorkerJobqueue]

list[GetWorkerJobqueue]: A list of job queue objects for the worker.

get_worker_list async

get_worker_list() -> list[GetWorkerWorkers]

Retrieves a list of all workers along with their status, queues, and job count.

Returns:

Type Description
list[GetWorkerWorkers]

list[GetWorkerWorkers]: A list of worker objects with their status, queues, and job counts.

get_worker_queues async

get_worker_queues(name: str) -> list[str]

Returns the active queues of the specified worker.

Parameters:

Name Type Description Default
name str

The name of the worker.

required

Returns:

Type Description
list[str]

list[str]: A list of active queues for the worker

pause_worker async

pause_worker(**kwargs) -> None

Pauses a worker by removing all queues from the workers specified in the names list, preventing jobs from being executed. If names not set than all workers are addressed.

Parameters:

Name Type Description Default
**kwargs

The names of the workers as a list[str].

{}

remove_queue_from_worker async

remove_queue_from_worker(id: str, queue_name: str) -> None

Removes a queue from the worker specified by the id.

Parameters:

Name Type Description Default
id str

The id of the worker.

required
queue_name str

The name of the queue to be removed.

required

Returns:

Type Description
None

None

reset_worker_queues async

reset_worker_queues(**kwargs) -> None

Adds all queues back to the worker specified in the names list. If names not set than all workers are addressed.

Parameters:

Name Type Description Default
**kwargs

The names of the workers as a list[str].

{}

cancel_job async

cancel_job(queue: Worker, job_id: str) -> bool

Revokes a given job.

Parameters:

Name Type Description Default
job_id str

The ID of the job

required

Returns:

Type Description
bool

Whether the revoke action was successful.

create_job async

create_job(queue: Worker, function: RegisteredTask, *args, **kwargs) -> CreateJobResponse

Enqueues a given task.

Parameters:

Name Type Description Default
queue Worker

The Queue to enqueue the task in

required
function RegisteredTask

The function to enqueue

required
args

Arguments passed to the job.

()
kwargs

Arguments passed to the job.

{}

Returns:

Type Description
CreateJobResponse

The job_id of the created job and a success status.

get_job_result async

get_job_result(queue: Worker, job_id: str) -> Any

Returns the result of the specified job

Parameters:

Name Type Description Default
job_id str

is the id of the job

required

Returns:

Type Description
Any

The Task result, i.e. the return of job executed

get_job_status async

get_job_status(queue: Worker, job_id: str) -> TaskStatus

Returns the status of the given job.

Parameters:

Name Type Description Default
job_id str

The ID of the job.

required

Returns:

Type Description
TaskStatus

The status of the job.