whatsnew-3.1.rst 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. .. _whatsnew-3.1:
  2. ===========================================
  3. What's new in Celery 3.1 (Cipater)
  4. ===========================================
  5. :Author: Ask Solem (ask at celeryproject.org)
  6. .. sidebar:: Change history
  7. What's new documents describe the changes in major versions,
  8. we also have a :ref:`changelog` that lists the changes in bugfix
  9. releases (0.0.x), while older series are archived under the :ref:`history`
  10. section.
  11. Celery is a simple, flexible and reliable distributed system to
  12. process vast amounts of messages, while providing operations with
  13. the tools required to maintain such a system.
  14. It's a task queue with focus on real-time processing, while also
  15. supporting task scheduling.
  16. Celery has a large and diverse community of users and contributors,
  17. you should come join us :ref:`on IRC <irc-channel>`
  18. or :ref:`our mailing-list <mailing-list>`.
  19. To read more about Celery you should go read the :ref:`introduction <intro>`.
  20. While this version is backward compatible with previous versions
  21. it's important that you read the following section.
  22. This version is officially supported on CPython 2.6, 2.7 and 3.3,
  23. and also supported on PyPy.
  24. .. _`website`: http://celeryproject.org/
  25. .. topic:: Table of Contents
  26. Make sure you read the important notes before upgrading to this version.
  27. .. contents::
  28. :local:
  29. :depth: 2
  30. Preface
  31. =======
  32. Deadlocks have long plagued our workers, and while uncommon they are
  33. not acceptable. They are also infamous for being extremely hard to diagnose
  34. and reproduce, so to make this job easier I wrote a stress test suite that
  35. bombards the worker with different tasks in an attempt to break it.
  36. What happens if thousands of worker child processes are killed every
  37. second? what if we also kill the broker connection every 10
  38. seconds? These are examples of what the stress test suite will do to the
  39. worker, and it reruns these tests using different configuration combinations
  40. to find edge case bugs.
  41. The end result was that I had to rewrite the prefork pool to avoid the use
  42. of the POSIX semaphore. This was extremely challenging, but after
  43. months of hard work the worker now finally passes the stress test suite.
  44. There's probably more bugs to find, but the good news is
  45. that we now have a tool to reproduce them, so should you be so unlucky to
  46. experience a bug then we'll write a test for it and squash it!
  47. Note that I have also moved many broker transports into experimental status:
  48. the only transports recommended for production use today is RabbitMQ and
  49. Redis.
  50. I don't have the resources to maintain all of them, so bugs are left
  51. unresolved. I wish that someone will step up and take responsibility for
  52. these transports or donate resources to improve them, but as the situation
  53. is now I don't think the quality is up to date with the rest of the code-base
  54. so I cannot recommend them for production use.
  55. The next version of Celery 3.2 will focus on performance and removing
  56. rarely used parts of the library. Work has also started on a new message
  57. protocol, supporting multiple languages and more. The initial draft can
  58. be found :ref:`here <protov2draft>`.
  59. This has probably been the hardest release I've worked on, so no
  60. introduction to this changelog would be complete without a massive
  61. thank you to everyone who contributed and helped me test it!
  62. Thank you for your support!
  63. *— Ask Solem*
  64. .. _v310-important:
  65. Important Notes
  66. ===============
  67. Dropped support for Python 2.5
  68. ------------------------------
  69. Celery now requires Python 2.6 or later.
  70. The new dual code base runs on both Python 2 and 3, without
  71. requiring the ``2to3`` porting tool.
  72. .. note::
  73. This is also the last version to support Python 2.6! From Celery 3.2 and
  74. onwards Python 2.7 or later will be required.
  75. Last version to enable Pickle by default
  76. ----------------------------------------
  77. Starting from Celery 3.2 the default serializer will be json.
  78. If you depend on pickle being accepted you should be prepared
  79. for this change by explicitly allowing your worker
  80. to consume pickled messages using the :setting:`CELERY_ACCEPT_CONTENT`
  81. setting:
  82. .. code-block:: python
  83. CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']
  84. Make sure you only select the serialization formats you'll actually be using,
  85. and make sure you have properly secured your broker from unwanted access
  86. (see the :ref:`Security Guide <guide-security>`).
  87. The worker will emit a deprecation warning if you don't define this setting.
  88. .. topic:: for Kombu users
  89. Kombu 3.0 no longer accepts pickled messages by default, so if you
  90. use Kombu directly then you have to configure your consumers:
  91. see the :ref:`Kombu 3.0 Changelog <kombu:version-3.0.0>` for more
  92. information.
  93. Old command-line programs removed and deprecated
  94. ------------------------------------------------
  95. Everyone should move to the new :program:`celery` umbrella
  96. command, so we are incrementally deprecating the old command names.
  97. In this version we've removed all commands that are not used
  98. in init scripts. The rest will be removed in 3.2.
  99. +-------------------+--------------+-------------------------------------+
  100. | Program | New Status | Replacement |
  101. +===================+==============+=====================================+
  102. | ``celeryd`` | *DEPRECATED* | :program:`celery worker` |
  103. +-------------------+--------------+-------------------------------------+
  104. | ``celerybeat`` | *DEPRECATED* | :program:`celery beat` |
  105. +-------------------+--------------+-------------------------------------+
  106. | ``celeryd-multi`` | *DEPRECATED* | :program:`celery multi` |
  107. +-------------------+--------------+-------------------------------------+
  108. | ``celeryctl`` | **REMOVED** | :program:`celery inspect|control` |
  109. +-------------------+--------------+-------------------------------------+
  110. | ``celeryev`` | **REMOVED** | :program:`celery events` |
  111. +-------------------+--------------+-------------------------------------+
  112. | ``camqadm`` | **REMOVED** | :program:`celery amqp` |
  113. +-------------------+--------------+-------------------------------------+
  114. If this is not a new installation then you may want to remove the old
  115. commands:
  116. .. code-block:: bash
  117. $ pip uninstall celery
  118. $ # repeat until it fails
  119. # ...
  120. $ pip uninstall celery
  121. $ pip install celery
  122. Please run :program:`celery --help` for help using the umbrella command.
  123. .. _v310-news:
  124. News
  125. ====
  126. Prefork Pool Improvements
  127. -------------------------
  128. These improvements are only active if you use an async capable
  129. transport. This means only RabbitMQ (AMQP) and Redis are supported
  130. at this point and other transports will still use the thread-based fallback
  131. implementation.
  132. - Pool is now using one IPC queue per child process.
  133. Previously the pool shared one queue between all child processes,
  134. using a POSIX semaphore as a mutex to achieve exclusive read and write
  135. access.
  136. The POSIX semaphore has now been removed and each child process
  137. gets a dedicated queue. This means that the worker will require more
  138. file descriptors (two descriptors per process), but it also means
  139. that performance is improved and we can send work to individual child
  140. processes.
  141. POSIX semaphores are not released when a process is killed, so killing
  142. processes could lead to a deadlock if it happened while the semaphore was
  143. acquired. There is no good solution to fix this, so the best option
  144. was to remove the semaphore.
  145. - Asynchronous write operations
  146. The pool now uses async I/O to send work to the child processes.
  147. - Lost process detection is now immediate.
  148. If a child process is killed or exits mysteriously the pool previously
  149. had to wait for 30 seconds before marking the task with a
  150. :exc:`~celery.exceptions.WorkerLostError`. It had to do this because
  151. the outqueue was shared between all processes, and the pool could not
  152. be certain whether the process completed the task or not. So an arbitrary
  153. timeout of 30 seconds was chosen, as it was believed that the outqueue
  154. would have been drained by this point.
  155. This timeout is no longer necessary, and so the task can be marked as
  156. failed as soon as the pool gets the notification that the process exited.
  157. - Rare race conditions fixed
  158. Most of these bugs were never reported to us, but was discovered while
  159. running the new stress test suite.
  160. Caveats
  161. ~~~~~~~
  162. .. topic:: Long running tasks
  163. The new pool will send tasks to a child process as long as the process
  164. inqueue is writable, and since the socket is buffered this means
  165. that the processes are, in effect, prefetching tasks.
  166. This benefits performance but it also means that other tasks may be stuck
  167. waiting for a long running task to complete::
  168. -> send T1 to Process A
  169. # A executes T1
  170. -> send T2 to Process B
  171. # B executes T2
  172. <- T2 complete
  173. -> send T3 to Process A
  174. # A still executing T1, T3 stuck in local buffer and
  175. # will not start until T1 returns
  176. The buffer size varies based on the operating system: some may
  177. have a buffer as small as 64kb but on recent Linux versions the buffer
  178. size is 1MB (can only be changed system wide).
  179. You can disable this prefetching behavior by enabling the :option:`-Ofair`
  180. worker option:
  181. .. code-block:: bash
  182. $ celery -A proj worker -l info -Ofair
  183. With this option enabled the worker will only write to workers that are
  184. available for work, disabling the prefetch behavior.
  185. .. topic:: Max tasks per child
  186. If a process exits and pool prefetch is enabled the worker may have
  187. already written many tasks to the process inqueue, and these tasks
  188. must then be moved back and rewritten to a new process.
  189. This is very expensive if you have ``--maxtasksperchild`` set to a low
  190. value (e.g. less than 10), so if you need to enable this option
  191. you should also enable ``-Ofair`` to turn off the prefetching behavior.
  192. Django supported out of the box
  193. -------------------------------
  194. Celery 3.0 introduced a shiny new API, but unfortunately did not
  195. have a solution for Django users.
  196. The situation changes with this version as Django is now supported
  197. in core and new Django users coming to Celery are now expected
  198. to use the new API directly.
  199. The Django community has a convention where there's a separate
  200. django-x package for every library, acting like a bridge between
  201. Django and the library.
  202. Having a separate project for Django users has been a pain for Celery,
  203. with multiple issue trackers and multiple documentation
  204. sources, and then lastly since 3.0 we even had different APIs.
  205. With this version we challenge that convention and Django users will
  206. use the same library, the same API and the same documentation as
  207. everyone else.
  208. There is no rush to port your existing code to use the new API,
  209. but if you would like to experiment with it you should know that:
  210. - You need to use a Celery application instance.
  211. The new Celery API introduced in 3.0 requires users to instantiate the
  212. library by creating an application:
  213. .. code-block:: python
  214. from celery import Celery
  215. app = Celery()
  216. - You need to explicitly integrate Celery with Django
  217. Celery will not automatically use the Django settings, so you can
  218. either configure Celery separately or you can tell it to use the Django
  219. settings with:
  220. .. code-block:: python
  221. app.config_from_object('django.conf:settings')
  222. Neither will it automatically traverse your installed apps to find task
  223. modules, but this still available as an option you must enable:
  224. .. code-block:: python
  225. from django.conf import settings
  226. app.autodiscover_tasks(settings.INSTALLED_APPS)
  227. - You no longer use ``manage.py``
  228. Instead you use the :program:`celery` command directly:
  229. .. code-block:: bash
  230. celery -A proj worker -l info
  231. For this to work your app module must store the :envvar:`DJANGO_SETTINGS_MODULE`
  232. environment variable, see the example in the :ref:`Django
  233. guide <django-first-steps>`.
  234. To get started with the new API you should first read the :ref:`first-steps`
  235. tutorial, and then you should read the Django specific instructions in
  236. :ref:`django-first-steps`.
  237. The fixes and improvements applied by the django-celery library are now
  238. automatically applied by core Celery when it detects that
  239. the :envvar:`DJANGO_SETTINGS_MODULE` environment variable is set.
  240. The distribution ships with a new example project using Django
  241. in :file:`examples/django`:
  242. http://github.com/celery/celery/tree/3.1/examples/django
  243. Some features still require the :mod:`django-celery` library:
  244. - Celery does not implement the Django database or cache result backends.
  245. - Celery does not ship with the database-based periodic task
  246. scheduler.
  247. .. note::
  248. If you're still using the old API when you upgrade to Celery 3.1
  249. then you must make sure that your settings module contains
  250. the ``djcelery.setup_loader()`` line, since this will
  251. no longer happen as a side-effect of importing the :mod:`djcelery`
  252. module.
  253. New users (or if you have ported to the new API) don't need the ``setup_loader``
  254. line anymore, and must make sure to remove it.
  255. Events are now ordered using logical time
  256. -----------------------------------------
  257. Keeping physical clocks in perfect sync is impossible, so using
  258. timestamps to order events in a distributed system is not reliable.
  259. Celery event messages have included a logical clock value for some time,
  260. but starting with this version that field is also used to order them.
  261. Also, events now record timezone information
  262. by including a new ``utcoffset`` field in the event message.
  263. This is a signed integer telling the difference from UTC time in hours,
  264. so e.g. an even sent from the Europe/London timezone in daylight savings
  265. time will have an offset of 1.
  266. :class:`@events.Receiver` will automatically convert the timestamps
  267. to the local timezone.
  268. .. note::
  269. The logical clock is synchronized with other nodes
  270. in the same cluster (neighbors), so this means that the logical
  271. epoch will start at the point when the first worker in the cluster
  272. starts.
  273. If all of the workers are shutdown the clock value will be lost
  274. and reset to 0, to protect against this you should specify
  275. a :option:`--statedb` so that the worker can persist the clock
  276. value at shutdown.
  277. You may notice that the logical clock is an integer value and
  278. increases very rapidly. Do not worry about the value overflowing
  279. though, as even in the most busy clusters it may take several
  280. millennia before the clock exceeds a 64 bits value.
  281. New worker node name format (``name@host``)
  282. -------------------------------------------
  283. Node names are now constructed by two elements: name and hostname separated by '@'.
  284. This change was made to more easily identify multiple instances running
  285. on the same machine.
  286. If a custom name is not specified then the
  287. worker will use the name 'celery' by default, resulting in a
  288. fully qualified node name of 'celery@hostname':
  289. .. code-block:: bash
  290. $ celery worker -n example.com
  291. celery@example.com
  292. To also set the name you must include the @:
  293. .. code-block:: bash
  294. $ celery worker -n worker1@example.com
  295. worker1@example.com
  296. The worker will identify itself using the fully qualified
  297. node name in events and broadcast messages, so where before
  298. a worker would identify itself as 'worker1.example.com', it will now
  299. use 'celery@worker1.example.com'.
  300. Remember that the ``-n`` argument also supports simple variable
  301. substitutions, so if the current hostname is *george.example.com*
  302. then the ``%h`` macro will expand into that:
  303. .. code-block:: bash
  304. $ celery worker -n worker1@%h
  305. worker1@george.example.com
  306. The available substitutions are as follows:
  307. +---------------+---------------------------------------+
  308. | Variable | Substitution |
  309. +===============+=======================================+
  310. | ``%h`` | Full hostname (including domain name) |
  311. +---------------+---------------------------------------+
  312. | ``%d`` | Domain name only |
  313. +---------------+---------------------------------------+
  314. | ``%n`` | Hostname only (without domain name) |
  315. +---------------+---------------------------------------+
  316. | ``%%`` | The character ``%`` |
  317. +---------------+---------------------------------------+
  318. Bound tasks
  319. -----------
  320. The task decorator can now create "bound tasks", which means that the
  321. task will receive the ``self`` argument.
  322. .. code-block:: python
  323. @app.task(bind=True)
  324. def send_twitter_status(self, oauth, tweet):
  325. try:
  326. twitter = Twitter(oauth)
  327. twitter.update_status(tweet)
  328. except (Twitter.FailWhaleError, Twitter.LoginError) as exc:
  329. raise self.retry(exc=exc)
  330. Using *bound tasks* is now the recommended approach whenever
  331. you need access to the task instance or request context.
  332. Previously one would have to refer to the name of the task
  333. instead (``send_twitter_status.retry``), but this could lead to problems
  334. in some configurations.
  335. Mingle: Worker synchronization
  336. ------------------------------
  337. The worker will now attempt to synchronize with other workers in
  338. the same cluster.
  339. Synchronized data currently includes revoked tasks and logical clock.
  340. This only happens at startup and causes a one second startup delay
  341. to collect broadcast responses from other workers.
  342. You can disable this bootstep using the ``--without-mingle`` argument.
  343. Gossip: Worker <-> Worker communication
  344. ---------------------------------------
  345. Workers are now passively subscribing to worker related events like
  346. heartbeats.
  347. This means that a worker knows what other workers are doing and
  348. can detect if they go offline. Currently this is only used for clock
  349. synchronization, but there are many possibilities for future additions
  350. and you can write extensions that take advantage of this already.
  351. Some ideas include consensus protocols, reroute task to best worker (based on
  352. resource usage or data locality) or restarting workers when they crash.
  353. We believe that this is a small addition but one that really opens
  354. up for amazing possibilities.
  355. You can disable this bootstep using the ``--without-gossip`` argument.
  356. Bootsteps: Extending the worker
  357. -------------------------------
  358. By writing bootsteps you can now easily extend the consumer part
  359. of the worker to add additional features, like custom message consumers.
  360. The worker has been using bootsteps for some time, but these were never
  361. documented. In this version the consumer part of the worker
  362. has also been rewritten to use bootsteps and the new :ref:`guide-extending`
  363. guide documents examples extending the worker, including adding
  364. custom message consumers.
  365. See the :ref:`guide-extending` guide for more information.
  366. .. note::
  367. Bootsteps written for older versions will not be compatible
  368. with this version, as the API has changed significantly.
  369. The old API was experimental and internal but should you be so unlucky
  370. to use it then please contact the mailing-list and we will help you port
  371. the bootstep to the new API.
  372. New RPC result backend
  373. ----------------------
  374. This new experimental version of the ``amqp`` result backend is a good
  375. alternative to use in classical RPC scenarios, where the process that initiates
  376. the task is always the process to retrieve the result.
  377. It uses Kombu to send and retrieve results, and each client
  378. uses a unique queue for replies to be sent to. This avoids
  379. the significant overhead of the original amqp result backend which creates
  380. one queue per task.
  381. By default results sent using this backend will not persist, so they won't
  382. survive a broker restart. You can enable
  383. the :setting:`CELERY_RESULT_PERSISTENT` setting to change that.
  384. .. code-block:: python
  385. CELERY_RESULT_BACKEND = 'rpc'
  386. CELERY_RESULT_PERSISTENT = True
  387. Note that chords are currently not supported by the RPC backend.
  388. Time limits can now be set by the client
  389. ----------------------------------------
  390. Two new options have been added to the Calling API: ``time_limit`` and
  391. ``soft_time_limit``:
  392. .. code-block:: python
  393. >>> res = add.apply_async((2, 2), time_limit=10, soft_time_limit=8)
  394. >>> res = add.subtask((2, 2), time_limit=10, soft_time_limit=8).delay()
  395. >>> res = add.s(2, 2).set(time_limit=10, soft_time_limit=8).delay()
  396. Contributed by Mher Movsisyan.
  397. Redis: Broadcast messages and virtual hosts
  398. -------------------------------------------
  399. Broadcast messages are currently seen by all virtual hosts when
  400. using the Redis transport. You can now fix this by enabling a prefix to all channels
  401. so that the messages are separated:
  402. .. code-block:: python
  403. BROKER_TRANSPORT_OPTIONS = {'fanout_prefix': True}
  404. Note that you'll not be able to communicate with workers running older
  405. versions or workers that does not have this setting enabled.
  406. This setting will be the default in a future version.
  407. Related to Issue #1490.
  408. :mod:`pytz` replaces ``python-dateutil`` dependency
  409. ---------------------------------------------------
  410. Celery no longer depends on the ``python-dateutil`` library,
  411. but instead a new dependency on the :mod:`pytz` library was added.
  412. The :mod:`pytz` library was already recommended for accurate timezone support.
  413. This also means that dependencies are the same for both Python 2 and
  414. Python 3, and that the :file:`requirements/default-py3k.txt` file has
  415. been removed.
  416. Support for Setuptools extra requirements
  417. -----------------------------------------
  418. Pip now supports the :mod:`setuptools` extra requirements format,
  419. so we have removed the old bundles concept, and instead specify
  420. setuptools extras.
  421. You install extras by specifying them inside brackets:
  422. .. code-block:: bash
  423. $ pip install celery[redis,mongodb]
  424. The above will install the dependencies for Redis and MongoDB. You can list
  425. as many extras as you want.
  426. .. warning::
  427. You can't use the ``celery-with-*`` packages anymore, as these will not be
  428. updated to use Celery 3.1.
  429. +-------------+-------------------------+---------------------------+
  430. | Extension | Requirement entry | Type |
  431. +=============+=========================+===========================+
  432. | Redis | ``celery[redis]`` | transport, result backend |
  433. +-------------+-------------------------+---------------------------+
  434. | MongoDB | ``celery[mongodb]`` | transport, result backend |
  435. +-------------+-------------------------+---------------------------+
  436. | CouchDB | ``celery[couchdb]`` | transport |
  437. +-------------+-------------------------+---------------------------+
  438. | Beanstalk | ``celery[beanstalk]`` | transport |
  439. +-------------+-------------------------+---------------------------+
  440. | ZeroMQ | ``celery[zeromq]`` | transport |
  441. +-------------+-------------------------+---------------------------+
  442. | Zookeeper | ``celery[zookeeper]`` | transport |
  443. +-------------+-------------------------+---------------------------+
  444. | SQLAlchemy | ``celery[sqlalchemy]`` | transport, result backend |
  445. +-------------+-------------------------+---------------------------+
  446. | librabbitmq | ``celery[librabbitmq]`` | transport (C amqp client) |
  447. +-------------+-------------------------+---------------------------+
  448. The complete list with examples is found in the :ref:`bundles` section.
  449. ``subtask.__call__()`` now executes the task directly
  450. -----------------------------------------------------
  451. A misunderstanding led to ``Signature.__call__`` being an alias of
  452. ``.delay`` but this does not conform to the calling API of ``Task`` which
  453. calls the underlying task method.
  454. This means that:
  455. .. code-block:: python
  456. @app.task
  457. def add(x, y):
  458. return x + y
  459. add.s(2, 2)()
  460. now does the same as calling the task directly:
  461. .. code-block:: python
  462. add(2, 2)
  463. In Other News
  464. -------------
  465. - Now depends on :ref:`Kombu 3.0 <kombu:version-3.0.0>`.
  466. - Now depends on :mod:`billiard` version 3.3.
  467. - Worker will now crash if running as the root user with pickle enabled.
  468. - Canvas: ``group.apply_async`` and ``chain.apply_async`` no longer starts
  469. separate task.
  470. That the group and chord primitives supported the "calling API" like other
  471. subtasks was a nice idea, but it was useless in practice and often
  472. confused users. If you still want this behavior you can define a
  473. task to do it for you.
  474. - New method ``Signature.freeze()`` can be used to "finalize"
  475. signatures/subtask.
  476. Regular signature:
  477. .. code-block:: python
  478. >>> s = add.s(2, 2)
  479. >>> result = s.freeze()
  480. >>> result
  481. <AsyncResult: ffacf44b-f8a1-44e9-80a3-703150151ef2>
  482. >>> s.delay()
  483. <AsyncResult: ffacf44b-f8a1-44e9-80a3-703150151ef2>
  484. Group:
  485. .. code-block:: python
  486. >>> g = group(add.s(2, 2), add.s(4, 4))
  487. >>> result = g.freeze()
  488. <GroupResult: e1094b1d-08fc-4e14-838e-6d601b99da6d [
  489. 70c0fb3d-b60e-4b22-8df7-aa25b9abc86d,
  490. 58fcd260-2e32-4308-a2ea-f5be4a24f7f4]>
  491. >>> g()
  492. <GroupResult: e1094b1d-08fc-4e14-838e-6d601b99da6d [70c0fb3d-b60e-4b22-8df7-aa25b9abc86d, 58fcd260-2e32-4308-a2ea-f5be4a24f7f4]>
  493. - New ability to specify additional command line options
  494. to the worker and beat programs.
  495. The :attr:`@Celery.user_options` attribute can be used
  496. to add additional command-line arguments, and expects
  497. optparse-style options:
  498. .. code-block:: python
  499. from celery import Celery
  500. from celery.bin import Option
  501. app = Celery()
  502. app.user_options['worker'].add(
  503. Option('--my-argument'),
  504. )
  505. See the :ref:`guide-extending` guide for more information.
  506. - All events now include a ``pid`` field, which is the process id of the
  507. process that sent the event.
  508. - Event heartbeats are now calculated based on the time when the event
  509. was received by the monitor, and not the time reported by the worker.
  510. This means that a worker with an out-of-sync clock will no longer
  511. show as 'Offline' in monitors.
  512. A warning is now emitted if the difference between the senders
  513. time and the internal time is greater than 15 seconds, suggesting
  514. that the clocks are out of sync.
  515. - Monotonic clock support.
  516. A monotonic clock is now used for timeouts and scheduling.
  517. The monotonic clock function is built-in starting from Python 3.4,
  518. but we also have fallback implementations for Linux and OS X.
  519. - :program:`celery worker` now supports a ``--detach`` argument to start
  520. the worker as a daemon in the background.
  521. - :class:`@events.Receiver` now sets a ``local_received`` field for incoming
  522. events, which is set to the time of when the event was received.
  523. - :class:`@events.Dispatcher` now accepts a ``groups`` argument
  524. which decides a white-list of event groups that will be sent.
  525. The type of an event is a string separated by '-', where the part
  526. before the first '-' is the group. Currently there are only
  527. two groups: ``worker`` and ``task``.
  528. A dispatcher instantiated as follows:
  529. .. code-block:: python
  530. app.events.Dispatcher(connection, groups=['worker'])
  531. will only send worker related events and silently drop any attempts
  532. to send events related to any other group.
  533. - New :setting:`BROKER_FAILOVER_STRATEGY` setting.
  534. This setting can be used to change the transport failover strategy,
  535. can either be a callable returning an iterable or the name of a
  536. Kombu built-in failover strategy. Default is "round-robin".
  537. Contributed by Matt Wise.
  538. - ``Result.revoke`` will no longer wait for replies.
  539. You can add the ``reply=True`` argument if you really want to wait for
  540. responses from the workers.
  541. - Better support for link and link_error tasks for chords.
  542. Contributed by Steeve Morin.
  543. - Worker: Now emits warning if the :setting:`CELERYD_POOL` setting is set
  544. to enable the eventlet/gevent pools.
  545. The `-P` option should always be used to select the eventlet/gevent pool
  546. to ensure that the patches are applied as early as possible.
  547. If you start the worker in a wrapper (like Django's manage.py)
  548. then you must apply the patches manually, e.g. by creating an alternative
  549. wrapper that monkey patches at the start of the program before importing
  550. any other modules.
  551. - There's a now an 'inspect clock' command which will collect the current
  552. logical clock value from workers.
  553. - `celery inspect stats` now contains the process id of the worker's main
  554. process.
  555. Contributed by Mher Movsisyan.
  556. - New remote control command to dump a workers configuration.
  557. Example:
  558. .. code-block:: bash
  559. $ celery inspect conf
  560. Configuration values will be converted to values supported by JSON
  561. where possible.
  562. Contributed by Mher Movisyan.
  563. - New settings :setting:`CELERY_EVENT_QUEUE_TTL` and
  564. :setting:`CELERY_EVENT_QUEUE_EXPIRES`.
  565. These control when a monitors event queue is deleted, and for how long
  566. events published to that queue will be visible. Only supported on
  567. RabbitMQ.
  568. - New Couchbase result backend.
  569. This result backend enables you to store and retrieve task results
  570. using `Couchbase`_.
  571. See :ref:`conf-couchbase-result-backend` for more information
  572. about configuring this result backend.
  573. Contributed by Alain Masiero.
  574. .. _`Couchbase`: http://www.couchbase.com
  575. - CentOS init script now supports starting multiple worker instances.
  576. See the script header for details.
  577. Contributed by Jonathan Jordan.
  578. - ``AsyncResult.iter_native`` now sets default interval parameter to 0.5
  579. Fix contributed by Idan Kamara
  580. - New setting :setting:`BROKER_LOGIN_METHOD`.
  581. This setting can be used to specify an alternate login method
  582. for the AMQP transports.
  583. Contributed by Adrien Guinet
  584. - The ``dump_conf`` remote control command will now give the string
  585. representation for types that are not JSON compatible.
  586. - Function `celery.security.setup_security` is now :func:`@setup_security`.
  587. - Task retry now propagates the message expiry value (Issue #980).
  588. The value is forwarded at is, so the expiry time will not change.
  589. To update the expiry time you would have to pass a new expires
  590. argument to ``retry()``.
  591. - Worker now crashes if a channel error occurs.
  592. Channel errors are transport specific and is the list of exceptions
  593. returned by ``Connection.channel_errors``.
  594. For RabbitMQ this means that Celery will crash if the equivalence
  595. checks for one of the queues in :setting:`CELERY_QUEUES` mismatches, which
  596. makes sense since this is a scenario where manual intervention is
  597. required.
  598. - Calling ``AsyncResult.get()`` on a chain now propagates errors for previous
  599. tasks (Issue #1014).
  600. - The parent attribute of ``AsyncResult`` is now reconstructed when using JSON
  601. serialization (Issue #1014).
  602. - Worker disconnection logs are now logged with severity warning instead of
  603. error.
  604. Contributed by Chris Adams.
  605. - ``events.State`` no longer crashes when it receives unknown event types.
  606. - SQLAlchemy Result Backend: New :setting:`CELERY_RESULT_DB_TABLENAMES`
  607. setting can be used to change the name of the database tables used.
  608. Contributed by Ryan Petrello.
  609. - SQLAlchemy Result Backend: Now calls ``enginge.dispose`` after fork
  610. (Issue #1564).
  611. If you create your own sqlalchemy engines then you must also
  612. make sure that these are closed after fork in the worker:
  613. .. code-block:: python
  614. from multiprocessing.util import register_after_fork
  615. engine = create_engine(…)
  616. register_after_fork(engine, engine.dispose)
  617. - A stress test suite for the Celery worker has been written.
  618. This is located in the ``funtests/stress`` directory in the git
  619. repository. There's a README file there to get you started.
  620. - The logger named ``celery.concurrency`` has been renamed to ``celery.pool``.
  621. - New command line utility ``celery graph``.
  622. This utility creates graphs in GraphViz dot format.
  623. You can create graphs from the currently installed bootsteps:
  624. .. code-block:: bash
  625. # Create graph of currently installed bootsteps in both the worker
  626. # and consumer namespaces.
  627. $ celery graph bootsteps | dot -T png -o steps.png
  628. # Graph of the consumer namespace only.
  629. $ celery graph bootsteps consumer | dot -T png -o consumer_only.png
  630. # Graph of the worker namespace only.
  631. $ celery graph bootsteps worker | dot -T png -o worker_only.png
  632. Or graphs of workers in a cluster:
  633. .. code-block:: bash
  634. # Create graph from the current cluster
  635. $ celery graph workers | dot -T png -o workers.png
  636. # Create graph from a specified list of workers
  637. $ celery graph workers nodes:w1,w2,w3 | dot -T png workers.png
  638. # also specify the number of threads in each worker
  639. $ celery graph workers nodes:w1,w2,w3 threads:2,4,6
  640. # …also specify the broker and backend URLs shown in the graph
  641. $ celery graph workers broker:amqp:// backend:redis://
  642. # …also specify the max number of workers/threads shown (wmax/tmax),
  643. # enumerating anything that exceeds that number.
  644. $ celery graph workers wmax:10 tmax:3
  645. - Changed the way that app instances are pickled.
  646. Apps can now define a ``__reduce_keys__`` method that is used instead
  647. of the old ``AppPickler`` attribute. E.g. if your app defines a custom
  648. 'foo' attribute that needs to be preserved when pickling you can define
  649. a ``__reduce_keys__`` as such:
  650. .. code-block:: python
  651. import celery
  652. class Celery(celery.Celery):
  653. def __init__(self, *args, **kwargs):
  654. super(Celery, self).__init__(*args, **kwargs)
  655. self.foo = kwargs.get('foo')
  656. def __reduce_keys__(self):
  657. return super(Celery, self).__reduce_keys__().update(
  658. foo=self.foo,
  659. )
  660. This is a much more convenient way to add support for pickling custom
  661. attributes. The old ``AppPickler`` is still supported but its use is
  662. discouraged and we would like to remove it in a future version.
  663. - Ability to trace imports for debugging purposes.
  664. The :envvar:`C_IMPDEBUG` can be set to trace imports as they
  665. occur:
  666. .. code-block:: bash
  667. $ C_IMDEBUG=1 celery worker -l info
  668. .. code-block:: bash
  669. $ C_IMPDEBUG=1 celery shell
  670. - Message headers now available as part of the task request.
  671. Example adding and retrieving a header value:
  672. .. code-block:: python
  673. @app.task(bind=True)
  674. def t(self):
  675. return self.request.headers.get('sender')
  676. >>> t.apply_async(headers={'sender': 'George Costanza'})
  677. - New :signal:`before_task_publish` signal dispatched before a task message
  678. is sent and can be used to modify the final message fields (Issue #1281).
  679. - New :signal:`after_task_publish` signal replaces the old :signal:`task_sent`
  680. signal.
  681. The :signal:`task_sent` signal is now deprecated and should not be used.
  682. - New :signal:`worker_process_shutdown` signal is dispatched in the
  683. prefork pool child processes as they exit.
  684. Contributed by Daniel M Taub.
  685. - ``celery.platforms.PIDFile`` renamed to :class:`celery.platforms.Pidfile`.
  686. - MongoDB Backend: Can now be configured using an URL:
  687. See :ref:`example-mongodb-result-config`.
  688. - MongoDB Backend: No longer using deprecated ``pymongo.Connection``.
  689. - MongoDB Backend: Now disables ``auto_start_request``.
  690. - MongoDB Backend: Now enables ``use_greenlets`` when eventlet/gevent is used.
  691. - ``subtask()`` / ``maybe_subtask()`` renamed to
  692. ``signature()``/``maybe_signature()``.
  693. Aliases still available for backwards compatibility.
  694. - The ``correlation_id`` message property is now automatically set to the
  695. id of the task.
  696. - The task message ``eta`` and ``expires`` fields now includes timezone
  697. information.
  698. - All result backends ``store_result``/``mark_as_*`` methods must now accept
  699. a ``request`` keyword argument.
  700. - Events now emit warning if the broken ``yajl`` library is used.
  701. - The :signal:`celeryd_init` signal now takes an extra keyword argument:
  702. ``option``.
  703. This is the mapping of parsed command line arguments, and can be used to
  704. prepare new preload arguments (``app.user_options['preload']``).
  705. - New callback: ``Celery.on_configure``.
  706. This callback is called when an app is about to be configured (a
  707. configuration key is required).
  708. - Worker: No longer forks on :sig:`HUP`.
  709. This means that the worker will reuse the same pid for better
  710. support with external process supervisors.
  711. Contributed by Jameel Al-Aziz.
  712. - Worker: The log message ``Got task from broker …`` was changed to
  713. ``Received task …``.
  714. - Worker: The log message ``Skipping revoked task …`` was changed
  715. to ``Discarding revoked task …``.
  716. - Optimization: Improved performance of ``ResultSet.join_native()``.
  717. Contributed by Stas Rudakou.
  718. - The :signal:`task_revoked` signal now accepts new ``request`` argument
  719. (Issue #1555).
  720. The revoked signal is dispatched after the task request is removed from
  721. the stack, so it must instead use the :class:`~celery.worker.job.Request`
  722. object to get information about the task.
  723. - Worker: New :option:`-X` command line argument to exclude queues
  724. (Issue #1399).
  725. The :option:`-X` argument is the inverse of the :option:`-Q` argument
  726. and accepts a list of queues to exclude (not consume from):
  727. .. code-block:: bash
  728. # Consume from all queues in CELERY_QUEUES, but not the 'foo' queue.
  729. $ celery worker -A proj -l info -X foo
  730. - Adds :envvar:`C_FAKEFORK` envvar for simple init script/multi debugging.
  731. This means that you can now do:
  732. .. code-block:: bash
  733. $ C_FAKEFORK=1 celery multi start 10
  734. or:
  735. .. code-block:: bash
  736. $ C_FAKEFORK=1 /etc/init.d/celeryd start
  737. to avoid the daemonization step to see errors that are not visible
  738. due to missing stdout/stderr.
  739. A ``dryrun`` command has been added to the generic init script that
  740. enables this option.
  741. - New public API to push and pop from the current task stack:
  742. :func:`celery.app.push_current_task` and
  743. :func:`celery.app.pop_current_task``.
  744. - ``RetryTaskError`` has been renamed to :exc:`~celery.exceptions.Retry`.
  745. The old name is still available for backwards compatibility.
  746. - New semi-predicate exception :exc:`~celery.exceptions.Reject`.
  747. This exception can be raised to ``reject``/``requeue`` the task message,
  748. see :ref:`task-semipred-reject` for examples.
  749. - :ref:`Semipredicates <task-semipredicates>` documented: (Retry/Ignore/Reject).
  750. .. _v310-removals:
  751. Scheduled Removals
  752. ==================
  753. - The ``BROKER_INSIST`` setting and the ``insist`` argument
  754. to ``~@connection`` is no longer supported.
  755. - The ``CELERY_AMQP_TASK_RESULT_CONNECTION_MAX`` setting is no longer
  756. supported.
  757. Use :setting:`BROKER_POOL_LIMIT` instead.
  758. - The ``CELERY_TASK_ERROR_WHITELIST`` setting is no longer supported.
  759. You should set the :class:`~celery.utils.mail.ErrorMail` attribute
  760. of the task class instead. You can also do this using
  761. :setting:`CELERY_ANNOTATIONS`:
  762. .. code-block:: python
  763. from celery import Celery
  764. from celery.utils.mail import ErrorMail
  765. class MyErrorMail(ErrorMail):
  766. whitelist = (KeyError, ImportError)
  767. def should_send(self, context, exc):
  768. return isinstance(exc, self.whitelist)
  769. app = Celery()
  770. app.conf.CELERY_ANNOTATIONS = {
  771. '*': {
  772. 'ErrorMail': MyErrorMails,
  773. }
  774. }
  775. - Functions that creates a broker connections no longer
  776. supports the ``connect_timeout`` argument.
  777. This can now only be set using the :setting:`BROKER_CONNECTION_TIMEOUT`
  778. setting. This is because functions no longer create connections
  779. directly, but instead get them from the connection pool.
  780. - The ``CELERY_AMQP_TASK_RESULT_EXPIRES`` setting is no longer supported.
  781. Use :setting:`CELERY_TASK_RESULT_EXPIRES` instead.
  782. .. _v310-deprecations:
  783. Deprecations
  784. ============
  785. See the :ref:`deprecation-timeline`.
  786. .. _v310-fixes:
  787. Fixes
  788. =====
  789. - AMQP Backend: join did not convert exceptions when using the json
  790. serializer.
  791. - Non-abstract task classes are now shared between apps (Issue #1150).
  792. Note that non-abstract task classes should not be used in the
  793. new API. You should only create custom task classes when you
  794. use them as a base class in the ``@task`` decorator.
  795. This fix ensure backwards compatibility with older Celery versions
  796. so that non-abstract task classes works even if a module is imported
  797. multiple times so that the app is also instantiated multiple times.
  798. - Worker: Workaround for Unicode errors in logs (Issue #427).
  799. - Task methods: ``.apply_async`` now works properly if args list is None
  800. (Issue #1459).
  801. - Eventlet/gevent/solo/threads pools now properly handles :exc:`BaseException`
  802. errors raised by tasks.
  803. - Autoscale and ``pool_grow``/``pool_shrink`` remote control commands
  804. will now also automatically increase and decrease the consumer prefetch count.
  805. Fix contributed by Daniel M. Taub.
  806. - ``celery control pool_`` commands did not coerce string arguments to int.
  807. - Redis/Cache chords: Callback result is now set to failure if the group
  808. disappeared from the database (Issue #1094).
  809. - Worker: Now makes sure that the shutdown process is not initiated multiple
  810. times.
  811. - Multi: Now properly handles both ``-f`` and ``--logfile`` options
  812. (Issue #1541).
  813. .. _v310-internal:
  814. Internal changes
  815. ================
  816. - Module ``celery.task.trace`` has been renamed to :mod:`celery.app.trace`.
  817. - Module ``celery.concurrency.processes`` has been renamed to
  818. :mod:`celery.concurrency.prefork`.
  819. - Classes that no longer fall back to using the default app:
  820. - Result backends (:class:`celery.backends.base.BaseBackend`)
  821. - :class:`celery.worker.WorkController`
  822. - :class:`celery.worker.Consumer`
  823. - :class:`celery.worker.job.Request`
  824. This means that you have to pass a specific app when instantiating
  825. these classes.
  826. - ``EventDispatcher.copy_buffer`` renamed to
  827. :meth:`@events.Dispatcher.extend_buffer`.
  828. - Removed unused and never documented global instance
  829. ``celery.events.state.state``.
  830. - :class:`@events.Receiver` is now a :class:`kombu.mixins.ConsumerMixin`
  831. subclass.
  832. - :class:`celery.apps.worker.Worker` has been refactored as a subclass of
  833. :class:`celery.worker.WorkController`.
  834. This removes a lot of duplicate functionality.
  835. - The ``Celery.with_default_connection`` method has been removed in favor
  836. of ``with app.connection_or_acquire``.
  837. - The ``celery.results.BaseDictBackend`` class has been removed and is replaced by
  838. :class:`celery.results.BaseBackend`.