whatsnew-3.1.rst 39 KB

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