Celery v0.9.0 (unstable) documentation
Task used internally by dmap_async() and TaskSet.map_async().
Execute an arbitrary function or object.
Note You probably want execute_remote() instead, which this is an internal component of.
The object must be pickleable, so you can’t use lambdas or functions defined in the REPL (that is the python shell, or ipython).
| Parameters: |
|
|---|
A periodic task is a task that behaves like a cron job.
| Raises NotImplementedError: | |
|---|---|
| if the run_every attribute is not defined. | |
Example
>>> from celery.task import tasks, PeriodicTask
>>> from datetime import timedelta
>>> class MyPeriodicTask(PeriodicTask):
... name = "my_periodic_task"
... run_every = timedelta(seconds=30)
...
... def run(self, **kwargs):
... logger = self.get_logger(**kwargs)
... logger.info("Running MyPeriodicTask")
A celery task.
All subclasses of Task must define the run() method, which is the actual method the celery daemon executes.
The run() method can take use of the default keyword arguments, as listed in the run() documentation.
The resulting class is callable, which if called will apply the run() method.
Execute this task at once, by blocking until the task has finished executing.
| Parameters: |
|
|---|---|
| Return type: |
Delay this task for execution by the celery daemon(s).
| Parameters: |
|
|---|
See celery.execute.apply_async() for more information.
| Return type: | celery.result.AsyncResult |
|---|
Shortcut to apply_async() but with star arguments, and doesn’t support the extra options.
| Parameters: |
|
|---|---|
| Return type: |
Get a celery task message consumer.
| Return type: | celery.messaging.TaskConsumer. |
|---|
Please be sure to close the AMQP connection when you’re done with this object. i.e.:
>>> consumer = self.get_consumer()
>>> # do something with consumer
>>> consumer.connection.close()
Get process-aware logger object.
Get a celery task message publisher.
| Return type: | celery.messaging.TaskPublisher. |
|---|
Please be sure to close the AMQP connection when you’re done with this object, i.e.:
>>> publisher = self.get_publisher()
>>> # do something with publisher
>>> publisher.connection.close()
Error handler.
This is run by the worker when the task fails.
| Parameters: |
|
|---|
The return value of this handler is ignored.
Retry handler.
This is run by the worker when the task is to be retried.
| Parameters: |
|
|---|
The return value of this handler is ignored.
Success handler.
This is run by the worker when the task executed successfully.
| Parameters: |
|
|---|
The return value of this handler is ignored.
Retry the task.
| Parameters: |
|
|---|---|
| Raises celery.exceptions.RetryTaskError: | |
To tell the worker that the task has been re-sent for retry. This always happens except if the throw keyword argument has been explicitly set to False. |
|
Example
>>> class TwitterPostStatusTask(Task):
...
... def run(self, username, password, message, **kwargs):
... twitter = Twitter(username, password)
... try:
... twitter.post_status(message)
... except twitter.FailWhale, exc:
... # Retry in 5 minutes.
... self.retry([username, password, message], kwargs,
... countdown=60 * 5, exc=exc)
The body of the task executed by the worker.
The following standard keyword arguments are reserved and is passed by the worker if the function/method supports them:
Additional standard keyword arguments may be added in the future. To take these default arguments, the task can either list the ones it wants explicitly or just take an arbitrary list of keyword arguments (**kwargs).
A task containing several subtasks, making it possible to track how many, or when all of the tasks has been completed.
| Parameters: |
|
|---|
Example
>>> from djangofeeds.tasks import RefreshFeedTask >>> taskset = TaskSet(RefreshFeedTask, args=[ ... ([], {"feed_url": "http://cnn.com/rss"}), ... ([], {"feed_url": "http://bbc.com/rss"}), ... ([], {"feed_url": "http://xkcd.com/rss"}) ... ])>>> taskset_result = taskset.run() >>> list_of_return_values = taskset_result.join()
Distribute processing of the arguments and collect the results asynchronously.
| Returns: | celery.result.AsyncResult instance. |
|---|
Run all tasks in the taskset.
| Returns: | A celery.result.TaskSetResult instance. |
|---|
Example
>>> ts = TaskSet(RefreshFeedTask, args=[
... (["http://foo.com/rss"], {}),
... (["http://bar.com/rss"], {}),
... ])
>>> result = ts.run()
>>> result.taskset_id
"d2c9b261-8eff-4bfb-8459-1e1b72063514"
>>> result.subtask_ids
["b4996460-d959-49c8-aeb9-39c530dcde25",
"598d2d18-ab86-45ca-8b4f-0779f5d6a3cb"]
>>> result.waiting()
True
>>> time.sleep(10)
>>> result.ready()
True
>>> result.successful()
True
>>> result.failed()
False
>>> result.join()
[True, True]
Metaclass for tasks.
Automatically registers the task in the task registry, except if the abstract attribute is set.
If no name attribute is provided, the name is automatically set to the name of the module it was defined in, and the class name.