Job Queue

The following queue classes are known to privacyIDEA

privacyidea.lib.queue.JOB_COLLECTOR = <privacyidea.lib.queue.JobCollector object>

A singleton is fine here, because it is only used at import time and once when a new app is created. Afterwards, the object is unused.

class privacyidea.lib.queue.JobCollector[source]

For most third-party job queue modules, the jobs are discovered by tracking all functions decorated with a @job decorator. However, in order to invoke the decorator, one usually needs to provide the queue configuration (e.g. the redis server) already. In privacyIDEA, we cannot do that, because the app config is not known yet – it will be known when create_app is called! Thus, we cannot directly use the @job decorator, but need a job collector that collects jobs in privacyIDEA code and registers them with the job queue module when create_app has been called.

property jobs

Create an instance of a BaseQueue subclass according to the app config’s PI_JOB_QUEUE_CLASS option and store it in the job_queue config. Register all collected jobs with this application. This instance is shared between threads! This function should only be called once per process.


app – privacyIDEA app

register_job(name, func, args, kwargs)[source]

Register a job with the collector.

  • name – unique name of the job

  • func – function of the job

  • args – arguments passed to the job queue’s register_job method

  • kwargs – keyword arguments passed to the job queue’s register_job method


Get the job queue registered with the current app. If no job queue is configured, raise a ServerError.


Return a boolean describing whether the current app has an app queue configured.

privacyidea.lib.queue.job(name, *args, **kwargs)[source]

Decorator to mark a job to be collected by the job collector. All arguments are passed to register_job.


Register the app app with the global job collector, if a PI_JOB_QUEUE_CLASS is non-empty. Do nothing otherwise.

privacyidea.lib.queue.wrap_job(name, result)[source]

Wrap a job and return a function that can be used like the original function. The returned function will always return result. This assumes that a queue is configured! Otherwise, calling the resulting function will fail with a ServerError.


a function Base class

class privacyidea.lib.queues.base.BaseQueue(options)[source]

A queue object represents an external job queue and is configured with a dictionary of options. It allows to register jobs, which are Python functions that may be executed outside of the request lifecycle. Every job is identified by a unique job name. It then allows to delegate (or “enqueue”) an invocation of a job (which is identified by its job name) to the external job queue. Currently, the queue only supports fire-and-forget jobs, i.e. jobs without any return value.

enqueue(name, args, kwargs)[source]

Schedule an invocation of a job on the external job queue.

  • name – Unique job name

  • args – Tuple of positional arguments

  • kwargs – Dictionary of keyword arguments



register_job(name, func)[source]

Add a job to the internal registry.

  • name – Unique job name

  • func – Function that should be executed by an external job queue