whatsnew-3.1.rst 37 KB

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