| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 | # -*- coding: utf-8 -*-from __future__ import absolute_import, unicode_literalsfrom time import sleepfrom celery import shared_taskfrom celery.utils.log import get_task_loggerlogger = get_task_logger(__name__)@shared_taskdef add(x, y):    """Add two numbers."""    return x + y@shared_taskdef 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_taskdef 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, ids(i)
 |