__init__.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. # -*- coding: utf-8 -*-"
  2. import sys
  3. import threading
  4. from celery.datastructures import ExceptionInfo
  5. from celery.exceptions import MaxRetriesExceededError, RetryTaskError
  6. from celery.execute.trace import TaskTrace
  7. from celery.registry import tasks, _unpickle_task
  8. from celery.result import EagerResult
  9. from celery.utils import mattrgetter, gen_unique_id, fun_takes_kwargs
  10. extract_exec_options = mattrgetter("queue", "routing_key",
  11. "exchange", "immediate",
  12. "mandatory", "priority",
  13. "serializer", "delivery_mode",
  14. "compression")
  15. class Context(threading.local):
  16. # Default context
  17. logfile = None
  18. loglevel = None
  19. id = None
  20. args = None
  21. kwargs = None
  22. retries = 0
  23. is_eager = False
  24. delivery_info = None
  25. taskset = None
  26. chord = None
  27. def update(self, d, **kwargs):
  28. self.__dict__.update(d, **kwargs)
  29. def clear(self):
  30. self.__dict__.clear()
  31. def get(self, key, default=None):
  32. try:
  33. return getattr(self, key)
  34. except AttributeError:
  35. return default
  36. class TaskType(type):
  37. """Metaclass for tasks.
  38. Automatically registers the task in the task registry, except
  39. if the `abstract` attribute is set.
  40. If no `name` attribute is provided, the name is automatically
  41. set to the name of the module it was defined in, and the class name.
  42. """
  43. def __new__(cls, name, bases, attrs):
  44. new = super(TaskType, cls).__new__
  45. task_module = attrs.get("__module__") or "__main__"
  46. # Abstract class: abstract attribute should not be inherited.
  47. if attrs.pop("abstract", None) or not attrs.get("autoregister", True):
  48. return new(cls, name, bases, attrs)
  49. # Automatically generate missing/empty name.
  50. autoname = False
  51. if not attrs.get("name"):
  52. try:
  53. module_name = sys.modules[task_module].__name__
  54. except KeyError: # pragma: no cover
  55. # Fix for manage.py shell_plus (Issue #366).
  56. module_name = task_module
  57. attrs["name"] = '.'.join([module_name, name])
  58. autoname = True
  59. # Because of the way import happens (recursively)
  60. # we may or may not be the first time the task tries to register
  61. # with the framework. There should only be one class for each task
  62. # name, so we always return the registered version.
  63. task_name = attrs["name"]
  64. if task_name not in tasks:
  65. task_cls = new(cls, name, bases, attrs)
  66. if autoname and task_module == "__main__" and task_cls.app.main:
  67. task_name = task_cls.name = '.'.join([task_cls.app.main, name])
  68. tasks.register(task_cls)
  69. task = tasks[task_name].__class__
  70. return task
  71. def __repr__(cls):
  72. return "<class Task of %s>" % (cls.app, )
  73. class BaseTask(object):
  74. """Task base class.
  75. When called tasks apply the :meth:`run` method. This method must
  76. be defined by all tasks (that is unless the :meth:`__call__` method
  77. is overridden).
  78. """
  79. __metaclass__ = TaskType
  80. MaxRetriesExceededError = MaxRetriesExceededError
  81. #: The application instance associated with this task class.
  82. app = None
  83. #: Name of the task.
  84. name = None
  85. #: If :const:`True` the task is an abstract base class.
  86. abstract = True
  87. #: If disabled the worker will not forward magic keyword arguments.
  88. #: Deprecated and scheduled for removal in v3.0.
  89. accept_magic_kwargs = False
  90. #: Request context (set when task is applied).
  91. request = Context()
  92. #: Destination queue. The queue needs to exist
  93. #: in :setting:`CELERY_QUEUES`. The `routing_key`, `exchange` and
  94. #: `exchange_type` attributes will be ignored if this is set.
  95. queue = None
  96. #: Overrides the apps default `routing_key` for this task.
  97. routing_key = None
  98. #: Overrides the apps default `exchange` for this task.
  99. exchange = None
  100. #: Overrides the apps default exchange type for this task.
  101. exchange_type = None
  102. #: Override the apps default delivery mode for this task. Default is
  103. #: `"persistent"`, but you can change this to `"transient"`, which means
  104. #: messages will be lost if the broker is restarted. Consult your broker
  105. #: manual for any additional delivery modes.
  106. delivery_mode = None
  107. #: Mandatory message routing.
  108. mandatory = False
  109. #: Request immediate delivery.
  110. immediate = False
  111. #: Default message priority. A number between 0 to 9, where 0 is the
  112. #: highest. Note that RabbitMQ does not support priorities.
  113. priority = None
  114. #: Maximum number of retries before giving up. If set to :const:`None`,
  115. #: it will **never** stop retrying.
  116. max_retries = 3
  117. #: Default time in seconds before a retry of the task should be
  118. #: executed. 3 minutes by default.
  119. default_retry_delay = 3 * 60
  120. #: Rate limit for this task type. Examples: :const:`None` (no rate
  121. #: limit), `"100/s"` (hundred tasks a second), `"100/m"` (hundred tasks
  122. #: a minute),`"100/h"` (hundred tasks an hour)
  123. rate_limit = None
  124. #: If enabled the worker will not store task state and return values
  125. #: for this task. Defaults to the :setting:`CELERY_IGNORE_RESULT`
  126. #: setting.
  127. ignore_result = False
  128. #: When enabled errors will be stored even if the task is otherwise
  129. #: configured to ignore results.
  130. store_errors_even_if_ignored = False
  131. #: If enabled an email will be sent to :setting:`ADMINS` whenever a task
  132. #: of this type fails.
  133. send_error_emails = False
  134. disable_error_emails = False # FIXME
  135. #: List of exception types to send error emails for.
  136. error_whitelist = ()
  137. #: The name of a serializer that are registered with
  138. #: :mod:`kombu.serialization.registry`. Default is `"pickle"`.
  139. serializer = "pickle"
  140. #: Hard time limit.
  141. #: Defaults to the :setting:`CELERY_TASK_TIME_LIMIT` setting.
  142. time_limit = None
  143. #: Soft time limit.
  144. #: Defaults to the :setting:`CELERY_TASK_SOFT_TIME_LIMIT` setting.
  145. soft_time_limit = None
  146. #: The result store backend used for this task.
  147. backend = None
  148. #: If disabled this task won't be registered automatically.
  149. autoregister = True
  150. #: If enabled the task will report its status as "started" when the task
  151. #: is executed by a worker. Disabled by default as the normal behaviour
  152. #: is to not report that level of granularity. Tasks are either pending,
  153. #: finished, or waiting to be retried.
  154. #:
  155. #: Having a "started" status can be useful for when there are long
  156. #: running tasks and there is a need to report which task is currently
  157. #: running.
  158. #:
  159. #: The application default can be overridden using the
  160. #: :setting:`CELERY_TRACK_STARTED` setting.
  161. track_started = False
  162. #: When enabled messages for this task will be acknowledged **after**
  163. #: the task has been executed, and not *just before* which is the
  164. #: default behavior.
  165. #:
  166. #: Please note that this means the task may be executed twice if the
  167. #: worker crashes mid execution (which may be acceptable for some
  168. #: applications).
  169. #:
  170. #: The application default can be overriden with the
  171. #: :setting:`CELERY_ACKS_LATE` setting.
  172. acks_late = False
  173. #: Default task expiry time.
  174. expires = None
  175. #: The type of task *(no longer used)*.
  176. type = "regular"
  177. def __call__(self, *args, **kwargs):
  178. return self.run(*args, **kwargs)
  179. def __reduce__(self):
  180. return (_unpickle_task, (self.name, ), None)
  181. def run(self, *args, **kwargs):
  182. """The body of the task executed by workers."""
  183. raise NotImplementedError("Tasks must define the run method.")
  184. @classmethod
  185. def get_logger(self, loglevel=None, logfile=None, propagate=False,
  186. **kwargs):
  187. """Get task-aware logger object."""
  188. if loglevel is None:
  189. loglevel = self.request.loglevel
  190. if logfile is None:
  191. logfile = self.request.logfile
  192. return self.app.log.setup_task_logger(loglevel=loglevel,
  193. logfile=logfile,
  194. propagate=propagate,
  195. task_name=self.name,
  196. task_id=self.request.id)
  197. @classmethod
  198. def establish_connection(self, connect_timeout=None):
  199. """Establish a connection to the message broker."""
  200. return self.app.broker_connection(connect_timeout=connect_timeout)
  201. @classmethod
  202. def get_publisher(self, connection=None, exchange=None,
  203. connect_timeout=None, exchange_type=None, **options):
  204. """Get a celery task message publisher.
  205. :rtype :class:`~celery.app.amqp.TaskPublisher`:
  206. .. warning::
  207. If you don't specify a connection, one will automatically
  208. be established for you, in that case you need to close this
  209. connection after use::
  210. >>> publisher = self.get_publisher()
  211. >>> # ... do something with publisher
  212. >>> publisher.connection.close()
  213. or used as a context::
  214. >>> with self.get_publisher() as publisher:
  215. ... # ... do something with publisher
  216. """
  217. if exchange is None:
  218. exchange = self.exchange
  219. if exchange_type is None:
  220. exchange_type = self.exchange_type
  221. connection = connection or self.establish_connection(connect_timeout)
  222. return self.app.amqp.TaskPublisher(connection=connection,
  223. exchange=exchange,
  224. exchange_type=exchange_type,
  225. routing_key=self.routing_key,
  226. **options)
  227. @classmethod
  228. def get_consumer(self, connection=None, connect_timeout=None):
  229. """Get message consumer.
  230. :rtype :class:`kombu.messaging.Consumer`:
  231. .. warning::
  232. If you don't specify a connection, one will automatically
  233. be established for you, in that case you need to close this
  234. connection after use::
  235. >>> consumer = self.get_consumer()
  236. >>> # do something with consumer
  237. >>> consumer.close()
  238. >>> consumer.connection.close()
  239. """
  240. connection = connection or self.establish_connection(connect_timeout)
  241. return self.app.amqp.TaskConsumer(connection=connection,
  242. exchange=self.exchange,
  243. routing_key=self.routing_key)
  244. @classmethod
  245. def delay(self, *args, **kwargs):
  246. """Star argument version of :meth:`apply_async`.
  247. Does not support the extra options enabled by :meth:`apply_async`.
  248. :param \*args: positional arguments passed on to the task.
  249. :param \*\*kwargs: keyword arguments passed on to the task.
  250. :returns :class:`celery.result.AsyncResult`:
  251. """
  252. return self.apply_async(args, kwargs)
  253. @classmethod
  254. def apply_async(self, args=None, kwargs=None, countdown=None,
  255. eta=None, task_id=None, publisher=None, connection=None,
  256. connect_timeout=None, router=None, expires=None, queues=None,
  257. **options):
  258. """Apply tasks asynchronously by sending a message.
  259. :keyword args: The positional arguments to pass on to the
  260. task (a :class:`list` or :class:`tuple`).
  261. :keyword kwargs: The keyword arguments to pass on to the
  262. task (a :class:`dict`)
  263. :keyword countdown: Number of seconds into the future that the
  264. task should execute. Defaults to immediate
  265. delivery (do not confuse with the
  266. `immediate` flag, as they are unrelated).
  267. :keyword eta: A :class:`~datetime.datetime` object describing
  268. the absolute time and date of when the task should
  269. be executed. May not be specified if `countdown`
  270. is also supplied. (Do not confuse this with the
  271. `immediate` flag, as they are unrelated).
  272. :keyword expires: Either a :class:`int`, describing the number of
  273. seconds, or a :class:`~datetime.datetime` object
  274. that describes the absolute time and date of when
  275. the task should expire. The task will not be
  276. executed after the expiration time.
  277. :keyword connection: Re-use existing broker connection instead
  278. of establishing a new one. The `connect_timeout`
  279. argument is not respected if this is set.
  280. :keyword connect_timeout: The timeout in seconds, before we give up
  281. on establishing a connection to the AMQP
  282. server.
  283. :keyword retry: If enabled sending of the task message will be retried
  284. in the event of connection loss or failure. Default
  285. is taken from the :setting:`CELERY_TASK_PUBLISH_RETRY`
  286. setting. Note you need to handle the
  287. publisher/connection manually for this to work.
  288. :keyword retry_policy: Override the retry policy used. See the
  289. :setting:`CELERY_TASK_PUBLISH_RETRY` setting.
  290. :keyword routing_key: The routing key used to route the task to a
  291. worker server. Defaults to the
  292. :attr:`routing_key` attribute.
  293. :keyword exchange: The named exchange to send the task to.
  294. Defaults to the :attr:`exchange` attribute.
  295. :keyword exchange_type: The exchange type to initalize the exchange
  296. if not already declared. Defaults to the
  297. :attr:`exchange_type` attribute.
  298. :keyword immediate: Request immediate delivery. Will raise an
  299. exception if the task cannot be routed to a worker
  300. immediately. (Do not confuse this parameter with
  301. the `countdown` and `eta` settings, as they are
  302. unrelated). Defaults to the :attr:`immediate`
  303. attribute.
  304. :keyword mandatory: Mandatory routing. Raises an exception if
  305. there's no running workers able to take on this
  306. task. Defaults to the :attr:`mandatory`
  307. attribute.
  308. :keyword priority: The task priority, a number between 0 and 9.
  309. Defaults to the :attr:`priority` attribute.
  310. :keyword serializer: A string identifying the default
  311. serialization method to use. Can be `pickle`,
  312. `json`, `yaml`, `msgpack` or any custom
  313. serialization method that has been registered
  314. with :mod:`kombu.serialization.registry`.
  315. Defaults to the :attr:`serializer` attribute.
  316. :keyword compression: A string identifying the compression method
  317. to use. Can be one of ``zlib``, ``bzip2``,
  318. or any custom compression methods registered with
  319. :func:`kombu.compression.register`. Defaults to
  320. the :setting:`CELERY_MESSAGE_COMPRESSION`
  321. setting.
  322. .. note::
  323. If the :setting:`CELERY_ALWAYS_EAGER` setting is set, it will
  324. be replaced by a local :func:`apply` call instead.
  325. """
  326. router = self.app.amqp.Router(queues)
  327. conf = self.app.conf
  328. if conf.CELERY_ALWAYS_EAGER:
  329. return self.apply(args, kwargs, task_id=task_id)
  330. options.setdefault("compression",
  331. conf.CELERY_MESSAGE_COMPRESSION)
  332. options = dict(extract_exec_options(self), **options)
  333. options = router.route(options, self.name, args, kwargs)
  334. expires = expires or self.expires
  335. publish = publisher or self.app.amqp.publisher_pool.acquire(block=True)
  336. evd = None
  337. if conf.CELERY_SEND_TASK_SENT_EVENT:
  338. evd = self.app.events.Dispatcher(channel=publish.channel,
  339. buffer_while_offline=False)
  340. try:
  341. task_id = publish.delay_task(self.name, args, kwargs,
  342. task_id=task_id,
  343. countdown=countdown,
  344. eta=eta, expires=expires,
  345. event_dispatcher=evd,
  346. **options)
  347. finally:
  348. if not publisher:
  349. publish.release()
  350. return self.AsyncResult(task_id)
  351. @classmethod
  352. def retry(self, args=None, kwargs=None, exc=None, throw=True,
  353. eta=None, countdown=None, max_retries=None, **options):
  354. """Retry the task.
  355. :param args: Positional arguments to retry with.
  356. :param kwargs: Keyword arguments to retry with.
  357. :keyword exc: Optional exception to raise instead of
  358. :exc:`~celery.exceptions.MaxRetriesExceededError`
  359. when the max restart limit has been exceeded.
  360. :keyword countdown: Time in seconds to delay the retry for.
  361. :keyword eta: Explicit time and date to run the retry at
  362. (must be a :class:`~datetime.datetime` instance).
  363. :keyword max_retries: If set, overrides the default retry limit.
  364. :keyword \*\*options: Any extra options to pass on to
  365. meth:`apply_async`.
  366. :keyword throw: If this is :const:`False`, do not raise the
  367. :exc:`~celery.exceptions.RetryTaskError` exception,
  368. that tells the worker to mark the task as being
  369. retried. Note that this means the task will be
  370. marked as failed if the task raises an exception,
  371. or successful if it returns.
  372. :raises celery.exceptions.RetryTaskError: To tell the worker that
  373. the task has been re-sent for retry. This always happens,
  374. unless the `throw` keyword argument has been explicitly set
  375. to :const:`False`, and is considered normal operation.
  376. **Example**
  377. .. code-block:: python
  378. >>> @task
  379. >>> def tweet(auth, message):
  380. ... twitter = Twitter(oauth=auth)
  381. ... try:
  382. ... twitter.post_status_update(message)
  383. ... except twitter.FailWhale, exc:
  384. ... # Retry in 5 minutes.
  385. ... return tweet.retry(countdown=60 * 5, exc=exc)
  386. Although the task will never return above as `retry` raises an
  387. exception to notify the worker, we use `return` in front of the retry
  388. to convey that the rest of the block will not be executed.
  389. """
  390. request = self.request
  391. if max_retries is None:
  392. max_retries = self.max_retries
  393. if args is None:
  394. args = request.args
  395. if kwargs is None:
  396. kwargs = request.kwargs
  397. delivery_info = request.delivery_info
  398. if delivery_info:
  399. options.setdefault("exchange", delivery_info.get("exchange"))
  400. options.setdefault("routing_key", delivery_info.get("routing_key"))
  401. if not eta and countdown is None:
  402. countdown = self.default_retry_delay
  403. options.update({"retries": request.retries + 1,
  404. "task_id": request.id,
  405. "countdown": countdown,
  406. "eta": eta})
  407. if max_retries is not None and options["retries"] > max_retries:
  408. raise exc or self.MaxRetriesExceededError(
  409. "Can't retry %s[%s] args:%s kwargs:%s" % (
  410. self.name, options["task_id"], args, kwargs))
  411. # If task was executed eagerly using apply(),
  412. # then the retry must also be executed eagerly.
  413. if request.is_eager:
  414. return self.apply(args=args, kwargs=kwargs, **options).get()
  415. self.apply_async(args=args, kwargs=kwargs, **options)
  416. if throw:
  417. raise RetryTaskError(
  418. eta and "Retry at %s" % (eta, )
  419. or "Retry in %s secs." % (countdown, ), exc)
  420. @classmethod
  421. def apply(self, args=None, kwargs=None, **options):
  422. """Execute this task locally, by blocking until the task
  423. returns.
  424. :param args: positional arguments passed on to the task.
  425. :param kwargs: keyword arguments passed on to the task.
  426. :keyword throw: Re-raise task exceptions. Defaults to
  427. the :setting:`CELERY_EAGER_PROPAGATES_EXCEPTIONS`
  428. setting.
  429. :rtype :class:`celery.result.EagerResult`:
  430. """
  431. args = args or []
  432. kwargs = kwargs or {}
  433. task_id = options.get("task_id") or gen_unique_id()
  434. retries = options.get("retries", 0)
  435. throw = self.app.either("CELERY_EAGER_PROPAGATES_EXCEPTIONS",
  436. options.pop("throw", None))
  437. # Make sure we get the task instance, not class.
  438. task = tasks[self.name]
  439. request = {"id": task_id,
  440. "retries": retries,
  441. "is_eager": True,
  442. "logfile": options.get("logfile"),
  443. "loglevel": options.get("loglevel", 0),
  444. "delivery_info": {"is_eager": True}}
  445. if self.accept_magic_kwargs:
  446. default_kwargs = {"task_name": task.name,
  447. "task_id": task_id,
  448. "task_retries": retries,
  449. "task_is_eager": True,
  450. "logfile": options.get("logfile"),
  451. "loglevel": options.get("loglevel", 0),
  452. "delivery_info": {"is_eager": True}}
  453. supported_keys = fun_takes_kwargs(task.run, default_kwargs)
  454. extend_with = dict((key, val)
  455. for key, val in default_kwargs.items()
  456. if key in supported_keys)
  457. kwargs.update(extend_with)
  458. trace = TaskTrace(task.name, task_id, args, kwargs,
  459. task=task, request=request, propagate=throw)
  460. retval = trace.execute()
  461. if isinstance(retval, ExceptionInfo):
  462. retval = retval.exception
  463. return EagerResult(task_id, retval, trace.status,
  464. traceback=trace.strtb)
  465. @classmethod
  466. def AsyncResult(self, task_id):
  467. """Get AsyncResult instance for this kind of task.
  468. :param task_id: Task id to get result for.
  469. """
  470. return self.app.AsyncResult(task_id, backend=self.backend,
  471. task_name=self.name)
  472. def update_state(self, task_id=None, state=None, meta=None):
  473. """Update task state.
  474. :param task_id: Id of the task to update.
  475. :param state: New state (:class:`str`).
  476. :param meta: State metadata (:class:`dict`).
  477. """
  478. if task_id is None:
  479. task_id = self.request.id
  480. self.backend.store_result(task_id, meta, state)
  481. def on_retry(self, exc, task_id, args, kwargs, einfo):
  482. """Retry handler.
  483. This is run by the worker when the task is to be retried.
  484. :param exc: The exception sent to :meth:`retry`.
  485. :param task_id: Unique id of the retried task.
  486. :param args: Original arguments for the retried task.
  487. :param kwargs: Original keyword arguments for the retried task.
  488. :keyword einfo: :class:`~celery.datastructures.ExceptionInfo`
  489. instance, containing the traceback.
  490. The return value of this handler is ignored.
  491. """
  492. pass
  493. def after_return(self, status, retval, task_id, args, kwargs, einfo):
  494. """Handler called after the task returns.
  495. :param status: Current task state.
  496. :param retval: Task return value/exception.
  497. :param task_id: Unique id of the task.
  498. :param args: Original arguments for the task that failed.
  499. :param kwargs: Original keyword arguments for the task
  500. that failed.
  501. :keyword einfo: :class:`~celery.datastructures.ExceptionInfo`
  502. instance, containing the traceback (if any).
  503. The return value of this handler is ignored.
  504. """
  505. if self.request.chord:
  506. self.backend.on_chord_part_return(self)
  507. def on_failure(self, exc, task_id, args, kwargs, einfo):
  508. """Error handler.
  509. This is run by the worker when the task fails.
  510. :param exc: The exception raised by the task.
  511. :param task_id: Unique id of the failed task.
  512. :param args: Original arguments for the task that failed.
  513. :param kwargs: Original keyword arguments for the task
  514. that failed.
  515. :keyword einfo: :class:`~celery.datastructures.ExceptionInfo`
  516. instance, containing the traceback.
  517. The return value of this handler is ignored.
  518. """
  519. pass
  520. def on_success(self, retval, task_id, args, kwargs):
  521. """Success handler.
  522. Run by the worker if the task executes successfully.
  523. :param retval: The return value of the task.
  524. :param task_id: Unique id of the executed task.
  525. :param args: Original arguments for the executed task.
  526. :param kwargs: Original keyword arguments for the executed task.
  527. The return value of this handler is ignored.
  528. """
  529. pass
  530. def execute(self, request, pool, loglevel, logfile, **kwargs):
  531. """The method the worker calls to execute the task.
  532. :param request: A :class:`~celery.worker.job.TaskRequest`.
  533. :param pool: A task pool.
  534. :param loglevel: Current loglevel.
  535. :param logfile: Name of the currently used logfile.
  536. :keyword consumer: The :class:`~celery.worker.consumer.Consumer`.
  537. """
  538. request.execute_using_pool(pool, loglevel, logfile)
  539. def __repr__(self):
  540. """`repr(task)`"""
  541. return "<@task: %s>" % (self.name, )
  542. @classmethod
  543. def subtask(cls, *args, **kwargs):
  544. """Returns :class:`~celery.task.sets.subtask` object for
  545. this task, wrapping arguments and execution options
  546. for a single task invocation."""
  547. from celery.task.sets import subtask
  548. return subtask(cls, *args, **kwargs)
  549. @property
  550. def __name__(self):
  551. return self.__class__.__name__