whatsnew-3.1.rst 42 KB

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