whatsnew-3.1.rst 41 KB

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