Module Contents#

class saq.worker.Worker(queue, functions, *, concurrency=10, cron_jobs=None, startup=None, shutdown=None, before_process=None, after_process=None, timers=None, dequeue_timeout=0)[source]#

Worker is used to process and monitor jobs.

  • queue (saq.queue.Queue) – instance of saq.queue.Queue

  • functions ([saq.types.Function | tuple[str, saq.types.Function]]) – list of async functions

  • concurrency (int) – number of jobs to process concurrently

  • cron_jobs ([saq.job.CronJob] | None) – List of CronJob instances.

  • startup (saq.types.ReceivesContext | None) – async function to call on startup

  • shutdown (saq.types.ReceivesContext | None) – async function to call on shutdown

  • before_process (saq.types.ReceivesContext | None) – async function to call before a job processes

  • after_process (saq.types.ReceivesContext | None) – async function to call after a job processes

  • timers (saq.types.PartialTimersDict | None) – dict with various timer overrides in seconds schedule: how often we poll to schedule jobs stats: how often to update stats sweep: how often to clean up stuck jobs abort: how often to check if a job is aborted

  • dequeue_timeout (float) – how long it will wait to dequeue

async start()[source]#

Start processing jobs and upkeep tasks.

Return type:


async stop()[source]#

Stop the worker and cleanup.

Return type:


async upkeep()[source]#

Start various upkeep tasks async.

Return type: