All models documented here should be imported directly from the pulpcore.plugin.tasking namespace.

class pulpcore.plugin.tasking.Task

The task which is currently executing.

Variables:job (str) – The RQ job associated with the task.

Append and save a non-fatal error for the currently executing task. Fatal errors should not use this. Instead they should raise an Exception, preferably one that inherits from :class: pulpcore.plugin.exceptions.PulpException.

This is saved in a structured way to the :attr: ~pulpcore.app.models.Task.non_fatal_errors attribute on the :class: ~pulpcore.app.models.Task model.

Parameters:error (Exception) – The non fatal error to be appended.
Raises:pulpcore.app.models.Task.DoesNotExist – If not currently running inside a task.
class pulpcore.plugin.tasking.WorkingDirectory

RQ Job working directory.

Path format: <worker-dir>/<task-id>


>>> with WorkingDirectory() as working_dir:
>>>     # directory created.
>>>     # process CWD = working_dir.path.
>>>     ....
>>> # directory deleted.
>>> # process CWD restored.
pulpcore.plugin.tasking.enqueue_with_reservation(func, resources, args=None, kwargs=None, options=None)

Enqueue a message to Pulp workers with a reservation.

This method provides normal enqueue functionality, while also requesting necessary locks for serialized urls. No two tasks that claim the same resource can execute concurrently. It accepts resources which it transforms into a list of urls (one for each resource).

This does not dispatch the task directly, but instead promises to dispatch it later by encapsulating the desired task through a call to a _queue_reserved_task() task. See the docblock on _queue_reserved_task() for more information on this.

This method creates a pulpcore.app.models.Task object. Pulp expects to poll on a task just after calling this method, so a Task entry needs to exist for it before it returns.

  • func (callable) – The function to be run by RQ when the necessary locks are acquired.
  • resources (list) – A list of resources to reserve guaranteeing that only one task reserves these resources. Each resource can be either a (str) resource URL or a (django.models.Model) resource instance.
  • args (tuple) – The positional arguments to pass on to the task.
  • kwargs (dict) – The keyword arguments to pass on to the task.
  • options (dict) – The options to be passed on to the task.

Returns (rq.job.job): An RQ Job instance as returned by RQ’s enqueue function

Raises:ValueError – When resources is an unsupported type.
pulpcore.plugin.tasking.exception_to_dict(exc, traceback=None)

Return a dictionary representation of an Exception.

  • exc (Exception) – Exception that is being serialized
  • traceback (str) – String representation of a traceback generated when the exception occurred.

dictionary representing the Exception

Return type:


pulpcore.plugin.tasking.get_current_job(connection=None, job_class=None)

Returns the Job instance that is currently being executed. If this function is invoked from outside a job context, None is returned.