pulpcore.plugin.tasking

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

class pulpcore.plugin.tasking.WorkingDirectory

Provide clean working directory for plugin writers on demand.

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

Examples

>>>
>>> with WorkingDirectory() as working_dir:
>>>     # directory created.
>>>     # process CWD = working_dir.path.
>>>     ....
>>> # directory deleted.
>>> # process CWD restored.
>>>

Create a WorkingDirectory.

Raises

RuntimeError – When used outside of an RQ task.

create()

Construct a unique working directory nested under the worker’s working directory.

pulpcore.plugin.tasking.add_and_remove(repository_pk, add_content_units, remove_content_units, base_version_pk=None)

Create a new repository version by adding and then removing content units.

Parameters
  • repository_pk (int) – The primary key for a Repository for which a new Repository Version should be created.

  • add_content_units (list) – List of PKs for Content that should be added to the previous Repository Version for this Repository.

  • remove_content_units (list) – List of PKs for:class:~pulpcore.app.models.Content that should be removed from the previous Repository Version for this Repository.

  • base_version_pk (int) – the primary key for a RepositoryVersion whose content will be used as the initial set of content for our new RepositoryVersion

pulpcore.plugin.tasking.dispatch(func, resources, args=None, kwargs=None, task_group=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 method creates a pulpcore.app.models.Task object and returns it.

Parameters
  • func (callable) – The function to be run by RQ when the necessary locks are acquired.

  • resources (list) – A list of resources to this task needs exclusive access to while running. Each resource can be either a str or a django.models.Model instance.

  • args (tuple) – The positional arguments to pass on to the task.

  • kwargs (dict) – The keyword arguments to pass on to the task.

  • task_group (pulpcore.app.models.TaskGroup) – A TaskGroup to add the created Task to.

Returns (pulpcore.app.models.Task): The Pulp Task that was created.

Raises

ValueError – When resources is an unsupported type.

pulpcore.plugin.tasking.enqueue_with_reservation(func, resources, args=None, kwargs=None, options=None, task_group=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.

Parameters
  • 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.

  • task_group (pulpcore.app.models.TaskGroup) – A TaskGroup to add the created Task to.

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.fs_publication_export(exporter_pk, publication_pk)

Export a publication to the file system.

Parameters
  • exporter_pk (str) – FilesystemExporter pk

  • publication_pk (str) – Publication pk

pulpcore.plugin.tasking.fs_repo_version_export(exporter_pk, repo_version_pk)

Export a repository version to the file system.

Parameters
  • exporter_pk (str) – FilesystemExporter pk

  • repo_version_pk (str) – RepositoryVersion pk