tasktronaut.backends package

Submodules

tasktronaut.backends.rq module

RQ Backend implementation for Tasktronaut process execution.

This module provides a concrete implementation of the Backend abstract base class using the RQ (Redis Queue) job queue library. It enables asynchronous execution of Tasktronaut processes with support for job dependencies and Redis-backed job persistence.

Workers executing Tasktronaut processes should use RqQueue (or a queue class including JobScopedReadyJobRegistryMixin) as their queue class, so that the jobs of a process are enqueued as soon as the jobs they depend on have finished. For example, rq worker --queue-class tasktronaut.backends.rq.RqQueue.

class tasktronaut.backends.rq.JobScopedReadyJobRegistry(name='default', connection=None, job_class=None, queue=None, serializer=None, death_penalty_class=None)

Bases: ReadyJobRegistry

Ready job registry whose claim of a job only conflicts with changes to that job.

RQ 3.0 claims each ready dependent job in an optimistic transaction which watches the queue’s shared ready job registry as well as the job. Every worker writes to that registry when readying or enqueueing any dependent job, so concurrent hand-offs of unrelated jobs abort each other, and the aborted job waits for worker maintenance, which can be up to ten minutes later. Meanwhile, the subsequent steps of the process sit in the deferred job registry.

Watching only the job keeps the guarantee against enqueueing a job twice: every successful claim, and every deletion or cancellation of a job, writes the job’s hash in its transaction, so a competing change to the same job still aborts the claim.

enqueue_jobs(job_ids)

Move ready jobs from the registry onto the queue.

Mirrors RQ 3.0’s rq.registry.ReadyJobRegistry.enqueue_jobs() except for the keys it watches; re-check it against RQ’s implementation when upgrading RQ. A job whose claim conflicts with a concurrent change to that job is skipped and left for cleanup().

Parameters:

job_ids (List[str]) – Ids of the jobs to enqueue, in enqueue order

Returns:

The jobs that were enqueued

Return type:

List[rq.job.Job]

class tasktronaut.backends.rq.JobScopedReadyJobRegistryMixin

Bases: object

Queue mixin which hands off ready dependent jobs via the job-scoped registry.

A worker enqueues the dependents of a finished job through the ready_job_registry of its queue class, so mix this into the queue class workers are configured with. For example, with django-rq:

class ApplicationQueue(JobScopedReadyJobRegistryMixin, DjangoRQ):
    pass

RQ = {"QUEUE_CLASS": "myapp.queues.ApplicationQueue"}
property ready_job_registry: JobScopedReadyJobRegistry
class tasktronaut.backends.rq.RqBackend(queue)

Bases: Backend

Backend implementation using RQ (Redis Queue) for process execution.

This backend enqueues process start, task, and completion callbacks to an RQ queue for asynchronous execution. It leverages RQ’s job dependency features to ensure proper task ordering and provides Redis-backed persistence of job state.

Parameters:

queue (rq.Queue) – The RQ Queue instance to which jobs will be enqueued

enqueue_perform_complete(identifier, module_name, definition_class, depends_on=None)

Enqueue a process completion callback to the RQ queue.

Schedules the execution of the process completion callback by enqueueing the perform_complete method to the configured RQ queue. The job will optionally depend on one or more other jobs before execution.

Parameters:
  • identifier (str) – Unique identifier for the process execution instance

  • module_name (str) – Fully qualified module name containing the process definition

  • definition_class (str) – Name of the process definition class to instantiate

  • depends_on (Optional[Union[Job, List[Job]]]) – Optional job or list of jobs that this job depends on. If provided, this job will not execute until all dependencies complete.

Returns:

RQ Job object representing the enqueued task

Return type:

Job

enqueue_perform_start(identifier, module_name, definition_class, depends_on=None)

Enqueue a process start callback.

Schedules the execution of the process start callback, which allows the process definition to perform initialization logic when execution begins.

Parameters:
  • identifier (str) – Unique identifier for the process execution instance

  • module_name (str) – Fully qualified module name containing the process definition

  • definition_class (str) – Name of the process definition class to instantiate

  • depends_on (Optional[Job]) – Optional job that this job depends on. If provided, this job will not execute until the dependency completes.

Returns:

Job object representing the enqueued task

Return type:

Job

enqueue_perform_task(identifier, module_name, definition_class, function_name, description, kwargs, depends_on=None)

Enqueue a process task for execution to the RQ queue.

Schedules the execution of a specific task function within a process definition by enqueueing the rq_perform_task method to the configured RQ queue. Uses a wrapper method to handle RQ-specific parameter handling.

Parameters:
  • identifier (str) – Unique identifier for the process execution instance

  • module_name (str) – Fully qualified module name containing the process definition

  • definition_class (str) – Name of the process definition class to instantiate

  • function_name (str) – Name of the task method to execute

  • description (Optional[str]) – Human-readable description of the task

  • kwargs (Dict[str, Any]) – Keyword arguments to pass to the task function

  • depends_on (Optional[Job]) – Optional job that this job depends on. If provided, this job will not execute until the dependency completes.

Returns:

RQ Job object representing the enqueued task

Return type:

Job

classmethod rq_perform_task(identifier, module_name, definition_class, function_name, task_description, task_kwargs)

Execute a process task from within an RQ job context.

This classmethod serves as the RQ job entry point for task execution. It retrieves the current RQ job, and delegates to the perform_task method.

Parameters:
  • identifier (str) – Unique identifier for the process execution instance

  • module_name (str) – Fully qualified module name containing the process definition

  • definition_class (str) – Name of the process definition class to instantiate

  • function_name (str) – Name of the task method to execute

  • task_description (Description) – Human-readable description of the task

  • task_kwargs (Dict[str, Any]) – Keyword arguments to pass to the task function

class tasktronaut.backends.rq.RqQueue(name='default', connection=None, default_timeout=None, is_async=True, job_class=None, serializer=None, death_penalty_class=<class 'rq.timeouts.UnixSignalDeathPenalty'>, **kwargs)

Bases: JobScopedReadyJobRegistryMixin, Queue

RQ queue which hands off ready dependent jobs via JobScopedReadyJobRegistry.

Use it as the queue class of workers executing Tasktronaut processes, e.g. rq worker --queue-class tasktronaut.backends.rq.RqQueue.

Module contents