whatsnew-2.6.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. .. _whatsnew-2.6:
  2. ==========================
  3. What's new in Celery 2.6
  4. ==========================
  5. Celery is a simple, flexible and reliable distributed system to
  6. process vast amounts of messages, while providing operations with
  7. the tools required to maintain such a system.
  8. It's a task queue with focus on real-time processing, while also
  9. supporting task scheduling.
  10. Celery has a large and diverse community of users and contributors,
  11. you should come join us :ref:`on IRC <irc-channel>`
  12. or :ref:`our mailing-list <mailing-list>`.
  13. To read more about Celery you should go read the :ref:`introduction <intro>`.
  14. While this version is backward compatible with previous versions
  15. it's important that you read the following section.
  16. If you use Celery in combination with Django you must also
  17. read the `django-celery changelog`_ and upgrade to `django-celery 2.6`_.
  18. This version is officially supported on CPython 2.5, 2.6, 2.7, 3.2 and 3.3,
  19. as well as PyPy and Jython.
  20. .. topic:: Highlights
  21. - A new and improved API, that is both simpler and more powerful.
  22. Everyone must read the new :ref:`first-steps` tutorial,
  23. and the new :ref:`next-steps` tutorial.
  24. There's no plans to deprecate the old API, so you don't have
  25. to be in a hurry to port your applications to the new API.
  26. - The worker is now thread-less, giving great performance improvements.
  27. - This is the last version to support Python 2.5
  28. - The new "Canvas" makes it easy to define complex workflows.
  29. Ever wanted to chain tasks together? This is possible, but
  30. not just that, now you can even chain together groups and chords,
  31. or even combine multiple chains.
  32. Read more in the :ref:`Canvas <guide-canvas>` user guide.
  33. .. _`website`: http://celeryproject.org/
  34. .. _`django-celery changelog`: http://bit.ly/djcelery-26-changelog
  35. .. _`django-celery 2.6`: http://pypi.python.org/pypi/django-celery/
  36. .. contents::
  37. :local:
  38. :depth: 2
  39. .. _v260-important:
  40. Important Notes
  41. ===============
  42. Eventloop
  43. ---------
  44. The worker is now running *without threads* when used with AMQP or Redis as a
  45. broker, resulting in::
  46. - Much better performance overall.
  47. - Fixes several edge case race conditions.
  48. - Sub-millisecond timer precision.
  49. - Faster shutdown times.
  50. The transports supported are: ``amqplib``, ``librabbitmq``, and ``redis``
  51. Hopefully this can be extended to include additional broker transports
  52. in the future.
  53. For increased reliability the :setting:`CELERY_FORCE_EXECV` setting is enabled
  54. by default if the eventloop is not used.
  55. Now depends on :mod:`billiard`.
  56. -------------------------------
  57. Billiard is a fork of the multiprocessing containing
  58. the no-execv patch by sbt (http://bugs.python.org/issue8713),
  59. and also contains the pool improvements previously located in Celery.
  60. This fork was necessary as changes to the C extension code was required
  61. for the no-execv patch to work.
  62. - Issue #625
  63. - Issue #627
  64. - Issue #640
  65. - `django-celery #122 <http://github.com/celery/django-celery/issues/122`
  66. - `django-celery #124 <http://github.com/celery/django-celery/issues/122`
  67. Last version to support Python 2.5
  68. ----------------------------------
  69. The 2.6 series will be last series to support Python 2.5.
  70. With several other distributions taking the step to discontinue
  71. Python 2.5 support, we feel that it is time too.
  72. Python 2.6 should be widely available at this point, and we urge
  73. you to upgrade, but if that is not possible you still have the option
  74. to continue using the Celery 2.6 series, and important bug fixes
  75. introduced in Celery 2.7 will be back-ported to Celery 2.6 upon request.
  76. .. _v260-news:
  77. News
  78. ====
  79. Chaining Tasks
  80. --------------
  81. Tasks can now have callbacks and errbacks, and dependencies are recorded
  82. - The task message format have been updated with two new extension keys
  83. Both keys can be empty/undefined or a list of subtasks.
  84. - ``callbacks``
  85. Applied if the task exits successfully, with the result
  86. of the task as an argument.
  87. - ``errbacks``
  88. Applied if an error occurred while executing the task,
  89. with the uuid of the task as an argument. Since it may not be possible
  90. to serialize the exception instance, it passes the uuid of the task
  91. instead. The uuid can then be used to retrieve the exception and
  92. traceback of the task from the result backend.
  93. - ``link`` and ``link_error`` keyword arguments has been added
  94. to ``apply_async``.
  95. These add callbacks and errbacks to the task, and
  96. you can read more about them at :ref:`calling-links`.
  97. - We now track what subtasks a task sends, and some result backends
  98. supports retrieving this information.
  99. - task.request.children
  100. Contains the result instances of the subtasks
  101. the currently executing task has applied.
  102. - AsyncResult.children
  103. Returns the tasks dependencies, as a list of
  104. ``AsyncResult``/``ResultSet`` instances.
  105. - AsyncResult.iterdeps
  106. Recursively iterates over the tasks dependencies,
  107. yielding `(parent, node)` tuples.
  108. Raises IncompleteStream if any of the dependencies
  109. has not returned yet.
  110. - AsyncResult.graph
  111. A ``DependencyGraph`` of the tasks dependencies.
  112. This can also be used to convert to dot format:
  113. .. code-block:: python
  114. with open('graph.dot') as fh:
  115. result.graph.to_dot(fh)
  116. which can than be used to produce an image::
  117. $ dot -Tpng graph.dot -o graph.png
  118. - A new special subtask called ``chain`` is also included::
  119. .. code-block:: python
  120. >>> from celery import chain
  121. # (2 + 2) * 8 / 2
  122. >>> res = chain(add.subtask((2, 2)),
  123. mul.subtask((8, )),
  124. div.subtask((2,))).apply_async()
  125. >>> res.get() == 16
  126. >>> res.parent.get() == 32
  127. >>> res.parent.parent.get() == 4
  128. - Adds :meth:`AsyncResult.get_leaf`
  129. Waits and returns the result of the leaf subtask.
  130. That is the last node found when traversing the graph,
  131. but this means that the graph can be 1-dimensional only (in effect
  132. a list).
  133. - Adds ``subtask.link(subtask)`` + ``subtask.link_error(subtask)``
  134. Shortcut to ``s.options.setdefault('link', []).append(subtask)``
  135. - Adds ``subtask.flatten_links()``
  136. Returns a flattened list of all dependencies (recursively)
  137. `group`/`chord`/`chain` are now subtasks
  138. ----------------------------------------
  139. - group is no longer an alias to TaskSet, but new alltogether,
  140. since it was very difficult to migrate the TaskSet class to become
  141. a subtask.
  142. - A new shortcut has been added to tasks::
  143. >>> task.s(arg1, arg2, kw=1)
  144. as a shortcut to::
  145. >>> task.subtask((arg1, arg2), {'kw': 1})
  146. - Tasks can be chained by using the ``|`` operator::
  147. >>> (add.s(2, 2), pow.s(2)).apply_async()
  148. - Subtasks can be "evaluated" using the ``~`` operator::
  149. >>> ~add.s(2, 2)
  150. 4
  151. >>> ~(add.s(2, 2) | pow.s(2))
  152. is the same as::
  153. >>> chain(add.s(2, 2), pow.s(2)).apply_async().get()
  154. - A new subtask_type key has been added to the subtask dicts
  155. This can be the string "chord", "group", "chain", "chunks",
  156. "xmap", or "xstarmap".
  157. - maybe_subtask now uses subtask_type to reconstruct
  158. the object, to be used when using non-pickle serializers.
  159. - The logic for these operations have been moved to dedicated
  160. tasks celery.chord, celery.chain and celery.group.
  161. - subtask no longer inherits from AttributeDict.
  162. It's now a pure dict subclass with properties for attribute
  163. access to the relevant keys.
  164. - The repr's now outputs how the sequence would like imperatively::
  165. >>> from celery import chord
  166. >>> (chord([add.s(i, i) for i in xrange(10)], xsum.s())
  167. | pow.s(2))
  168. tasks.xsum([tasks.add(0, 0),
  169. tasks.add(1, 1),
  170. tasks.add(2, 2),
  171. tasks.add(3, 3),
  172. tasks.add(4, 4),
  173. tasks.add(5, 5),
  174. tasks.add(6, 6),
  175. tasks.add(7, 7),
  176. tasks.add(8, 8),
  177. tasks.add(9, 9)]) | tasks.pow(2)
  178. Additional control commands made public
  179. ---------------------------------------
  180. - ``add_consumer``/``cancel_consumer``
  181. Tells workers to consume from a new queue, or cancel consuming from a
  182. queue. This command has also been changed so that the worker remembers
  183. the queues added, so that the change will persist even if
  184. the connection is re-connected.
  185. These commands are available programmatically as
  186. :meth:`@control.add_consumer` / :meth:`@control.cancel_consumer`:
  187. .. code-block:: python
  188. >>> celery.control.add_consumer(queue_name,
  189. ... destination=['w1.example.com'])
  190. >>> celery.control.cancel_consumer(queue_name,
  191. ... destination=['w1.example.com'])
  192. or using the :program:`celery control` command::
  193. $ celery control -d w1.example.com add_consumer queue
  194. $ celery control -d w1.example.com cancel_consumer queue
  195. .. note::
  196. Remember that a control command without *destination* will be
  197. sent to **all workers**.
  198. - ``autoscale``
  199. Tells workers with `--autoscale` enabled to change autoscale
  200. max/min concurrency settings.
  201. This command is available programmatically as :meth:`@control.autoscale`:
  202. .. code-block:: python
  203. >>> celery.control.autoscale(max=10, min=5,
  204. ... destination=['w1.example.com'])
  205. or using the :program:`celery control` command::
  206. $ celery control -d w1.example.com autoscale 10 5
  207. - ``pool_grow``/``pool_shrink``
  208. Tells workers to add or remove pool processes.
  209. These commands are available programmatically as
  210. :meth:`@control.pool_grow` / :meth:`@control.pool_shrink`:
  211. .. code-block:: python
  212. >>> celery.control.pool_grow(2, destination=['w1.example.com'])
  213. >>> celery.contorl.pool_shrink(2, destination=['w1.example.com'])
  214. or using the :program:`celery control` command::
  215. $ celery control -d w1.example.com pool_grow 2
  216. $ celery control -d w1.example.com pool_shrink 2
  217. - :program:`celery control` now supports ``rate_limit`` & ``time_limit``
  218. commands.
  219. See ``celery control --help`` for details.
  220. Crontab now supports Day of Month, and Month of Year arguments
  221. --------------------------------------------------------------
  222. See the updated list of examples at :ref:`beat-crontab`.
  223. Immutable subtasks
  224. ------------------
  225. ``subtask``'s can now be immutable, which means that the arguments
  226. will not be modified when calling callbacks::
  227. >>> chain(add.s(2, 2), clear_static_electricity.si())
  228. means it will not receive the argument of the parent task,
  229. and ``.si()`` is a shortcut to::
  230. >>> clear_static_electricity.subtask(immutable=True)
  231. Logging Improvements
  232. --------------------
  233. Logging support now conforms better with best practices.
  234. - Classes used by the worker no longer uses app.get_default_logger, but uses
  235. `celery.utils.log.get_logger` which simply gets the logger not setting the
  236. level, and adds a NullHandler.
  237. - Loggers are no longer passed around, instead every module using logging
  238. defines a module global logger that is used throughout.
  239. - All loggers inherit from a common logger called "celery".
  240. - Before task.get_logger would setup a new logger for every task,
  241. and even set the loglevel. This is no longer the case.
  242. - Instead all task loggers now inherit from a common "celery.task" logger
  243. that is set up when programs call `setup_logging_subsystem`.
  244. - Instead of using LoggerAdapter to augment the formatter with
  245. the task_id and task_name field, the task base logger now use
  246. a special formatter adding these values at runtime from the
  247. currently executing task.
  248. - In fact, ``task.get_logger`` is no longer recommended, it is better
  249. to add module-level logger to your tasks module.
  250. For example, like this:
  251. .. code-block:: python
  252. from celery.utils.log import get_task_logger
  253. logger = get_task_logger(__name__)
  254. @celery.task()
  255. def add(x, y):
  256. logger.debug('Adding %r + %r' % (x, y))
  257. return x + y
  258. The resulting logger will then inherit from the ``"celery.task"`` logger
  259. so that the current task name and id is included in logging output.
  260. - Redirected output from stdout/stderr is now logged to a "celery.redirected"
  261. logger.
  262. - In addition a few warnings.warn have been replaced with logger.warn.
  263. - Now avoids the 'no handlers for logger multiprocessing' warning
  264. Task registry no longer global
  265. ------------------------------
  266. Every Celery instance now has its own task registry.
  267. You can make apps share registries by specifying it::
  268. >>> app1 = Celery()
  269. >>> app2 = Celery(tasks=app1.tasks)
  270. Note that tasks are shared between registries by default, so that
  271. tasks will be added to every subsequently created task registry.
  272. As an alternative tasks can be private to specific task registries
  273. by setting the ``shared`` argument to the ``@task`` decorator::
  274. @celery.task(shared=False)
  275. def add(x, y):
  276. return x + y
  277. Abstract tasks are now lazily bound.
  278. ------------------------------------
  279. The :class:`~celery.task.Task` class is no longer bound to an app
  280. by default, it will first be bound (and configured) when
  281. a concrete subclass is created.
  282. This means that you can safely import and make task base classes,
  283. without also initializing the app environment::
  284. from celery.task import Task
  285. class DebugTask(Task):
  286. abstract = True
  287. def __call__(self, *args, **kwargs):
  288. print('CALLING %r' % (self, ))
  289. return self.run(*args, **kwargs)
  290. >>> DebugTask
  291. <unbound DebugTask>
  292. >>> @celery1.task(base=DebugTask)
  293. ... def add(x, y):
  294. ... return x + y
  295. >>> add.__class__
  296. <class add of <Celery default:0x101510d10>>
  297. Lazy task decorators
  298. --------------------
  299. The ``@task`` decorator is now lazy when used with custom apps.
  300. That is, if ``accept_magic_kwargs`` is enabled (herby called "compat mode"), the task
  301. decorator executes inline like before, however for custom apps the @task
  302. decorator now returns a special PromiseProxy object that is only evaluated
  303. on access.
  304. All promises will be evaluated when `app.finalize` is called, or implicitly
  305. when the task registry is first used.
  306. Smart `--app` option
  307. --------------------
  308. The :option:`--app` option now 'auto-detects'
  309. - If the provided path is a module it tries to get an
  310. attribute named 'celery'.
  311. - If the provided path is a package it tries
  312. to import a submodule named 'celery',
  313. and get the celery attribute from that module.
  314. E.g. if you have a project named 'proj' where the
  315. celery app is located in 'from proj.celery import celery',
  316. then the following will be equivalent::
  317. $ celery worker --app=proj
  318. $ celery worker --app=proj.celery:
  319. $ celery worker --app=proj.celery:celery
  320. In Other News
  321. -------------
  322. - New :setting:`CELERYD_WORKER_LOST_WAIT` to control the timeout in
  323. seconds before :exc:`billiard.WorkerLostError` is raised
  324. when a worker can not be signalled (Issue #595).
  325. Contributed by Brendon Crawford.
  326. - Redis event monitor queues are now automatically deleted (Issue #436).
  327. - App instance factory methods have been converted to be cached
  328. descriptors that creates a new subclass on access.
  329. This means that e.g. ``celery.Worker`` is an actual class
  330. and will work as expected when::
  331. class Worker(celery.Worker):
  332. ...
  333. - New signal: :signal:`task-success`.
  334. - Multiprocessing logs are now only emitted if the :envvar:`MP_LOG`
  335. environment variable is set.
  336. - The Celery instance can now be created with a broker URL
  337. .. code-block:: python
  338. celery = Celery(broker='redis://')
  339. - Result backends can now be set using an URL
  340. Currently only supported by redis. Example use::
  341. CELERY_RESULT_BACKEND = 'redis://localhost/1'
  342. - Heartbeat frequency now every 5s, and frequency sent with event
  343. The heartbeat frequency is now available in the worker event messages,
  344. so that clients can decide when to consider workers offline based on
  345. this value.
  346. - Module celery.actors has been removed, and will be part of cl instead.
  347. - Introduces new ``celery`` command, which is an entrypoint for all other
  348. commands.
  349. The main for this command can be run by calling ``celery.start()``.
  350. - Annotations now supports decorators if the key startswith '@'.
  351. E.g.:
  352. .. code-block:: python
  353. def debug_args(fun):
  354. @wraps(fun)
  355. def _inner(*args, **kwargs):
  356. print('ARGS: %r' % (args, ))
  357. return _inner
  358. CELERY_ANNOTATIONS = {
  359. 'tasks.add': {'@__call__': debug_args},
  360. }
  361. Also tasks are now always bound by class so that
  362. annotated methods end up being bound.
  363. - Bugreport now available as a command and broadcast command
  364. - Get it from a Python repl::
  365. >>> import celery
  366. >>> print(celery.bugreport())
  367. - Using the ``celery`` command-line program::
  368. $ celery report
  369. - Get it from remote workers::
  370. $ celery inspect report
  371. - Module ``celery.log`` moved to :mod:`celery.app.log`.
  372. - Module ``celery.task.control`` moved to :mod:`celery.app.control`.
  373. - New signal: :signal:`task-revoked`
  374. Sent in the main process when the task is revoked or terminated.
  375. - ``AsyncResult.task_id`` renamed to ``AsyncResult.id``
  376. - ``TasksetResult.taskset_id`` renamed to ``.id``
  377. - ``xmap(task, sequence)`` and ``xstarmap(task, sequence)``
  378. Returns a list of the results applying the task function to every item
  379. in the sequence.
  380. Example::
  381. >>> from celery import xstarmap
  382. >>> xstarmap(add, zip(range(10), range(10)).apply_async()
  383. [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
  384. - ``chunks(task, sequence, chunksize)``
  385. - ``group.skew(start=, stop=, step=)``
  386. Skew will skew the countdown for the individual tasks in a group,
  387. e.g. with a group::
  388. >>> g = group(add.s(i, i) for i in xrange(10))
  389. Skewing the tasks from 0 seconds to 10 seconds::
  390. >>> g.skew(stop=10)
  391. Will have the first task execute in 0 seconds, the second in 1 second,
  392. the third in 2 seconds and so on.
  393. - 99% test Coverage
  394. - :setting:`CELERY_QUEUES` can now be a list/tuple of :class:`~kombu.Queue`
  395. instances.
  396. Internally :attr:`@amqp.queues` is now a mapping of name/Queue instances,
  397. instead of converting on the fly.
  398. * Can now specify connection for :class:`@control.inspect`.
  399. .. code-block:: python
  400. from kombu import Connection
  401. i = celery.control.inspect(connection=Connection('redis://'))
  402. i.active_queues()
  403. * Module :mod:`celery.app.task` is now a module instead of a package.
  404. The setup.py install script will try to remove the old package,
  405. if that doesn't work for some reason you have to remove
  406. it manually, you can do so by executing the command::
  407. $ rm -r $(dirname $(python -c '
  408. import celery;print(celery.__file__)'))/app/task/
  409. * :setting:`CELERY_FORCE_EXECV` is now enabled by default.
  410. If the old behavior is wanted the setting can be set to False,
  411. or the new :option:`--no-execv` to :program:`celery worker`.
  412. * Deprecated module ``celery.conf`` has been removed.
  413. * The :setting:`CELERY_TIMEZONE` now always require the :mod:`pytz`
  414. library to be installed (exept if the timezone is set to `UTC`).
  415. * The Tokyo Tyrant backend has been removed and is no longer supported.
  416. * Now uses :func:`~kombu.common.maybe_declare` to cache queue declarations.
  417. * There is no longer a global default for the
  418. :setting:`CELERYBEAT_MAX_LOOP_INTERVAL` setting, it is instead
  419. set by individual schedulers.
  420. * Worker: now truncates very long message bodies in error reports.
  421. * :envvar:`CELERY_BENCH` environment variable, will now also list
  422. memory usage statistics at worker shutdown.
  423. * Worker: now only ever use a single timer for all timing needs,
  424. and instead set different priorities.
  425. Internals
  426. ---------
  427. * Compat modules are now generated dynamically upon use.
  428. These modules are ``celery.messaging``, ``celery.log``,
  429. ``celery.decorators`` and ``celery.registry``.
  430. * :mod:`celery.utils` refactored into multiple modules:
  431. :mod:`celery.utils.text`
  432. :mod:`celery.utils.imports`
  433. :mod:`celery.utils.functional`
  434. * Now using :mod:`kombu.utils.encoding` instead of
  435. `:mod:`celery.utils.encoding`.
  436. * Renamed module ``celery.routes`` -> :mod:`celery.app.routes`.
  437. * Renamed package ``celery.db`` -> :mod:`celery.backends.database`.
  438. * Renamed module ``celery.abstract`` -> :mod:`celery.worker.abstract`.
  439. * Command-line docs are now parsed from the module docstrings.
  440. * Test suite directory has been reorganized.
  441. * :program:`setup.py` now reads docs from the :file:`requirements/` directory.
  442. .. _v260-experimental:
  443. Experimental
  444. ============
  445. :mod:`celery.contrib.methods`: Task decorator for methods
  446. ----------------------------------------------------------
  447. This is an experimental module containing a task
  448. decorator, and a task decorator filter, that can be used
  449. to create tasks out of methods::
  450. from celery.contrib.methods import task_method
  451. class Counter(object):
  452. def __init__(self):
  453. self.value = 1
  454. @celery.task(name='Counter.increment', filter=task_method)
  455. def increment(self, n=1):
  456. self.value += 1
  457. return self.value
  458. See :mod:`celery.contrib.methods` for more information.
  459. .. _v260-unscheduled-removals:
  460. Unscheduled Removals
  461. ====================
  462. Usually we don't make backward incompatible removals,
  463. but these removals should have no major effect.
  464. - The following settings have been renamed:
  465. - ``CELERYD_ETA_SCHEDULER`` -> ``CELERYD_TIMER``
  466. - ``CELERYD_ETA_SCHEDULER_PRECISION`` -> ``CELERYD_TIMER_PRECISION``
  467. .. _v260-deprecations:
  468. Deprecations
  469. ============
  470. See the :ref:`deprecation-timeline`.
  471. The following undocumented API's has been moved:
  472. - ``control.inspect.add_consumer`` -> :meth:`@control.add_consumer`.
  473. - ``control.inspect.cancel_consumer`` -> :meth:`@control.cancel_consumer`.
  474. - ``control.inspect.enable_events`` -> :meth:`@control.enable_events`.
  475. - ``control.inspect.disable_events`` -> :meth:`@control.disable_events`.
  476. This way ``inspect()`` is only used for commands that do not
  477. modify anything, while idempotent control commands that make changes
  478. are on the control objects.
  479. Fixes
  480. =====
  481. - Retry sqlalchemy backend operations on DatabaseError/OperationalError
  482. (Issue #634)