|
@@ -159,68 +159,11 @@ class PeriodicTask(Task):
|
|
|
|
|
|
|
|
|
|
def task(*args, **kwargs):
|
|
def task(*args, **kwargs):
|
|
- """Decorator to create a task class out of any callable.
|
|
|
|
-
|
|
|
|
- **Examples**
|
|
|
|
-
|
|
|
|
- .. code-block:: python
|
|
|
|
-
|
|
|
|
- @task()
|
|
|
|
- def refresh_feed(url):
|
|
|
|
- return Feed.objects.get(url=url).refresh()
|
|
|
|
-
|
|
|
|
- With setting extra options and using retry.
|
|
|
|
-
|
|
|
|
- .. code-block:: python
|
|
|
|
-
|
|
|
|
- @task(max_retries=10)
|
|
|
|
- def refresh_feed(url):
|
|
|
|
- try:
|
|
|
|
- return Feed.objects.get(url=url).refresh()
|
|
|
|
- except socket.error as exc:
|
|
|
|
- refresh_feed.retry(exc=exc)
|
|
|
|
-
|
|
|
|
- Calling the resulting task:
|
|
|
|
-
|
|
|
|
- >>> refresh_feed('http://example.com/rss') # Regular
|
|
|
|
- <Feed: http://example.com/rss>
|
|
|
|
- >>> refresh_feed.delay('http://example.com/rss') # Async
|
|
|
|
- <AsyncResult: 8998d0f4-da0b-4669-ba03-d5ab5ac6ad5d>
|
|
|
|
- """
|
|
|
|
|
|
+ """Deprecated decorators, please use :meth:`~@task`."""
|
|
return current_app.task(*args, **dict({'accept_magic_kwargs': False,
|
|
return current_app.task(*args, **dict({'accept_magic_kwargs': False,
|
|
'base': Task}, **kwargs))
|
|
'base': Task}, **kwargs))
|
|
|
|
|
|
|
|
|
|
def periodic_task(*args, **options):
|
|
def periodic_task(*args, **options):
|
|
- """Decorator to create a task class out of any callable.
|
|
|
|
-
|
|
|
|
- .. admonition:: Examples
|
|
|
|
-
|
|
|
|
- .. code-block:: python
|
|
|
|
-
|
|
|
|
- @task()
|
|
|
|
- def refresh_feed(url):
|
|
|
|
- return Feed.objects.get(url=url).refresh()
|
|
|
|
-
|
|
|
|
- With setting extra options and using retry.
|
|
|
|
-
|
|
|
|
- .. code-block:: python
|
|
|
|
-
|
|
|
|
- from celery.task import current
|
|
|
|
-
|
|
|
|
- @task(exchange='feeds')
|
|
|
|
- def refresh_feed(url):
|
|
|
|
- try:
|
|
|
|
- return Feed.objects.get(url=url).refresh()
|
|
|
|
- except socket.error as exc:
|
|
|
|
- current.retry(exc=exc)
|
|
|
|
-
|
|
|
|
- Calling the resulting task:
|
|
|
|
-
|
|
|
|
- >>> refresh_feed('http://example.com/rss') # Regular
|
|
|
|
- <Feed: http://example.com/rss>
|
|
|
|
- >>> refresh_feed.delay('http://example.com/rss') # Async
|
|
|
|
- <AsyncResult: 8998d0f4-da0b-4669-ba03-d5ab5ac6ad5d>
|
|
|
|
-
|
|
|
|
- """
|
|
|
|
|
|
+ """Deprecated decorator, please use :setting:`CELERYBEAT_SCHEDULE`."""
|
|
return task(**dict({'base': PeriodicTask}, **options))
|
|
return task(**dict({'base': PeriodicTask}, **options))
|