14.2.1.6. Job Queue¶
The following queue classes are known to eduMFA
- edumfa.lib.queue.JOB_COLLECTOR = <edumfa.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 edumfa.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 eduMFA, we cannot do that, because the app config is not known yet – it will be known whencreate_app
is called! Thus, we cannot directly use the @job decorator, but need a job collector that collects jobs in eduMFA code and registers them with the job queue module whencreate_app
has been called.- property jobs¶
- register_app(app)[source]¶
Create an instance of a
BaseQueue
subclass according to the app config’sEDUMFA_JOB_QUEUE_CLASS
option and store it in thejob_queue
config. Register all collected jobs with this application. This instance is shared between threads! This function should only be called once per process.- Parameters:
app – eduMFA app
- edumfa.lib.queue.get_job_queue()[source]¶
Get the job queue registered with the current app. If no job queue is configured, raise a ServerError.
- edumfa.lib.queue.has_job_queue()[source]¶
Return a boolean describing whether the current app has an app queue configured.
- edumfa.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
.
- edumfa.lib.queue.register_app(app)[source]¶
Register the app
app
with the global job collector, if a EDUMFA_JOB_QUEUE_CLASS is non-empty. Do nothing otherwise.
- edumfa.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.- Returns:
a function
14.2.1.6.2. Base class¶
- class edumfa.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.