This document describes an older version of Celery (2.5). For the latest stable version please go here.

celery.task.sets

celery.task.sets

Creating and applying groups of tasks.

copyright:
  1. 2009 - 2012 by Ask Solem.
license:

BSD, see LICENSE for more details.

class celery.task.sets.TaskSet(tasks=None, app=None, Publisher=None)

A task containing several subtasks, making it possible to track how many, or when all of the tasks have been completed.

Parameters:tasks – A list of subtask instances.

Example:

>>> urls = ("http://cnn.com/rss", "http://bbc.co.uk/rss")
>>> taskset = TaskSet(refresh_feed.subtask((url, )) for url in urls)
>>> taskset_result = taskset.apply_async()
>>> list_of_return_values = taskset_result.join()  # *expensive*
apply(taskset_id=None)

Applies the taskset locally by blocking until all tasks return.

apply_async(connection=None, connect_timeout=None, publisher=None, taskset_id=None)

Apply taskset.

tasks
total = None

Total number of subtasks in this set.

celery.task.sets.group

alias of TaskSet

celery.task.sets.maybe_subtask(t)
class celery.task.sets.subtask(task=None, args=None, kwargs=None, options=None, **ex)

Class that wraps the arguments and execution options for a single task invocation.

Used as the parts in a TaskSet or to safely pass tasks around as callbacks.

Parameters:
  • task – Either a task class/instance, or the name of a task.
  • args – Positional arguments to apply.
  • kwargs – Keyword arguments to apply.
  • options – Additional options to Task.apply_async().

Note that if the first argument is a dict, the other arguments will be ignored and the values in the dict will be used instead.

>>> s = subtask("tasks.add", args=(2, 2))
>>> subtask(s)
{"task": "tasks.add", args=(2, 2), kwargs={}, options={}}
apply(args=(), kwargs={}, **options)

Apply this task locally.

apply_async(args=(), kwargs={}, **options)

Apply this task asynchronously.

clone(args=(), kwargs={}, **options)
delay(*argmerge, **kwmerge)

Shortcut to apply_async(argmerge, kwargs).

type

Previous topic

celery.task.base

Next topic

celery.task.chords

This Page