184.108.40.206. 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¶
For most third-party job queue modules, the jobs are discovered by tracking all functions decorated with a
@jobdecorator. 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_appis 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_apphas been called.
- property jobs¶
Create an instance of a
BaseQueuesubclass according to the app config’s
PI_JOB_QUEUE_CLASSoption and store it in the
job_queueconfig. 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)¶
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
kwargs – keyword arguments passed to the job queue’s
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)¶
Decorator to mark a job to be collected by the job collector. All arguments are passed to
Register the app
appwith the global job collector, if a PI_JOB_QUEUE_CLASS is non-empty. Do nothing otherwise.
- privacyidea.lib.queue.wrap_job(name, result)¶
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.
220.127.116.11.2. Base class¶
- class privacyidea.lib.queues.base.BaseQueue(options)¶
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)¶
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)¶
Add a job to the internal registry.
name – Unique job name
func – Function that should be executed by an external job queue