12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- # -*- coding: utf-8 -*-
- from time import sleep
- from celery import shared_task
- from celery.utils.log import get_task_logger
- logger = get_task_logger(__name__)
- @shared_task
- def add(x, y):
- """Add two numbers."""
- return x + y
- @shared_task
- def print_unicode(log_message='hå它 valmuefrø', print_message='hiöäüß'):
- """Task that both logs and print strings containing funny characters."""
- logger.warning(log_message)
- print(print_message)
- @shared_task
- def sleeping(i, **_):
- """Task sleeping for ``i`` seconds, and returning nothing."""
- sleep(i)
- @shared_task(bind=True)
- def ids(self, i):
- """Returns a tuple of ``root_id``, ``parent_id`` and
- the argument passed as ``i``."""
- return self.request.root_id, self.request.parent_id, i
- @shared_task(bind=True)
- def collect_ids(self, res, i):
- """Used as a callback in a chain or group where the previous tasks
- are :task:`ids`: returns a tuple of::
- (previous_result, (root_id, parent_id, i))
- """
- return res, (self.request.root_id, self.request.parent_id, i)
|