whatsnew-4.0.rst 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. .. _whatsnew-4.0:
  2. ===========================================
  3. What's new in Celery 4.0 (0Today8)
  4. ===========================================
  5. :Author: Ask Solem (``ask at celeryproject.org``)
  6. .. sidebar:: Change history
  7. What's new documents describe the changes in major versions,
  8. we also have a :ref:`changelog` that lists the changes in bugfix
  9. releases (0.0.x), while older series are archived under the :ref:`history`
  10. section.
  11. Celery is a simple, flexible and reliable distributed system to
  12. process vast amounts of messages, while providing operations with
  13. the tools required to maintain such a system.
  14. It's a task queue with focus on real-time processing, while also
  15. supporting task scheduling.
  16. Celery has a large and diverse community of users and contributors,
  17. you should come join us :ref:`on IRC <irc-channel>`
  18. or :ref:`our mailing-list <mailing-list>`.
  19. To read more about Celery you should go read the :ref:`introduction <intro>`.
  20. While this version is backward compatible with previous versions
  21. it's important that you read the following section.
  22. This version is officially supported on CPython 2.7, 3.4 and 3.5.
  23. and also supported on PyPy.
  24. .. _`website`: http://celeryproject.org/
  25. .. topic:: Table of Contents
  26. Make sure you read the important notes before upgrading to this version.
  27. .. contents::
  28. :local:
  29. :depth: 2
  30. Preface
  31. =======
  32. XXX To be written
  33. Wall of Contributors
  34. --------------------
  35. XXX Needs update
  36. Aaron McMillin, Adam Renberg, Adrien Guinet, Ahmet Demir, Aitor Gómez-Goiri,
  37. Albert Wang, Alex Koshelev, Alex Rattray, Alex Williams, Alexander Koshelev,
  38. Alexander Lebedev, Alexander Oblovatniy, Alexey Kotlyarov, Ali Bozorgkhan,
  39. Alice Zoë Bevan–McGregor, Allard Hoeve, Alman One, Andrea Rabbaglietti,
  40. Andrea Rosa, Andrei Fokau, Andrew Rodionoff, Andriy Yurchuk,
  41. Aneil Mallavarapu, Areski Belaid, Artyom Koval, Ask Solem, Balthazar Rouberol,
  42. Berker Peksag, Bert Vanderbauwhede, Brian Bouterse, Chris Duryee, Chris Erway,
  43. Chris Harris, Chris Martin, Corey Farwell, Craig Jellick, Cullen Rhodes,
  44. Dallas Marlow, Daniel Wallace, Danilo Bargen, Davanum Srinivas, Dave Smith,
  45. David Baumgold, David Harrigan, David Pravec, Dennis Brakhane, Derek Anderson,
  46. Dmitry Malinovsky, Dudás Ádám, Dustin J. Mitchell, Ed Morley, Fatih Sucu,
  47. Feanil Patel, Felix Schwarz, Fernando Rocha, Flavio Grossi, Frantisek Holop,
  48. Gao Jiangmiao, Gerald Manipon, Gilles Dartiguelongue, Gino Ledesma,
  49. Hank John, Hogni Gylfason, Ilya Georgievsky, Ionel Cristian Mărieș,
  50. James Pulec, Jared Lewis, Jason Veatch, Jasper Bryant-Greene, Jeremy Tillman,
  51. Jocelyn Delalande, Joe Jevnik, John Anderson, John Kirkham, John Whitlock,
  52. Joshua Harlow, Juan Rossi, Justin Patrin, Kai Groner, Kevin Harvey,
  53. Konstantinos Koukopoulos, Kouhei Maeda, Kracekumar Ramaraju,
  54. Krzysztof Bujniewicz, Latitia M. Haskins, Len Buckens, Lorenzo Mancini,
  55. Lucas Wiman, Luke Pomfrey, Marcio Ribeiro, Marin Atanasov Nikolov,
  56. Mark Parncutt, Maxime Vdb, Mher Movsisyan, Michael (:github_user:`michael-k`),
  57. Michael Duane Mooring, Michael Permana, Mickaël Penhard, Mike Attwood,
  58. Morton Fox, Môshe van der Sterre, Nat Williams, Nathan Van Gheem, Nik Nyby,
  59. Omer Katz, Omer Korner, Ori Hoch, Paul Pearce, Paulo Bu, Philip Garnero,
  60. Piotr Maślanka, Radek Czajka, Raghuram Srinivasan, Randy Barlow,
  61. Rodolfo Carvalho, Roger Hu, Rongze Zhu, Ross Deane, Ryan Luckie,
  62. Rémy Greinhofer, Samuel Jaillet, Sergey Azovskov, Sergey Tikhonov,
  63. Seungha Kim, Steve Peak, Sukrit Khera, Tadej Janež, Tewfik Sadaoui,
  64. Thomas French, Thomas Grainger, Tobias Schottdorf, Tocho Tochev,
  65. Valentyn Klindukh, Vic Kumar, Vladimir Bolshakov, Vladimir Gorbunov,
  66. Wayne Chang, Wil Langford, Will Thompson, William King, Yury Selivanov,
  67. Zoran Pavlovic, 許邱翔, :github_user:`allenling`, :github_user:`bee-keeper`,
  68. :github_user:`ffeast`, :github_user:`flyingfoxlee`, :github_user:`gdw2`,
  69. :github_user:`gitaarik`, :github_user:`hankjin`, :github_user:`m-vdb`,
  70. :github_user:`mdk`, :github_user:`nokrik`, :github_user:`ocean1`,
  71. :github_user:`orlo666`, :github_user:`raducc`, :github_user:`wanglei`,
  72. :github_user:`worldexception`.
  73. .. _v400-important:
  74. Important Notes
  75. ===============
  76. Dropped support for Python 2.6
  77. ------------------------------
  78. Celery now requires Python 2.7 or later,
  79. and also drops support for Python 3.3 so supported versions are:
  80. - CPython 2.7
  81. - CPython 3.4
  82. - CPython 3.5
  83. - PyPy 4.0 (``pypy2``)
  84. - PyPy 2.4 (``pypy3``)
  85. Last major version to support Python 2
  86. --------------------------------------
  87. Starting from Celery 5.0 only Python 3.6+ will be supported.
  88. To make sure you're not affected by this change you should pin
  89. the Celery version in your requirements file, either to a specific
  90. version: ``celery==4.0.0``, or a range: ``celery>=4.0,<5.0``.
  91. Dropping support for Python 2 will enable us to remove massive
  92. amounts of compatibility code, and going with Python 3.6 allows
  93. us to take advantage of typing, async/await, asyncio, ++, for which
  94. there are no convenient alternatives in older versions.
  95. Celery 4.x will continue to work on Python 2.7, 3.4, 3.5; just as Celery 3.x
  96. still works on Python 2.6.
  97. Removed features
  98. ----------------
  99. - Microsoft Windows is no longer supported.
  100. - Jython is no longer supported.
  101. Features removed for simplicity
  102. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. - Webhook task machinery (``celery.task.http``) has been removed.
  104. Nowadays it's easy to use the :pypi:`requests` module to write
  105. webhook tasks manually. We would love to use requests but we
  106. are simply unable to as there's a very vocal 'anti-dependency'
  107. mob in the Python community
  108. If you need backwards compatibility
  109. you can simply copy + paste the 3.1 version of the module and make sure
  110. it's imported by the worker:
  111. https://github.com/celery/celery/blob/3.1/celery/task/http.py
  112. - Task no longer sends error emails.
  113. This also removes support for ``app.mail_admins``, and any functionality
  114. related to sending emails.
  115. - ``celery.contrib.batches`` has been removed.
  116. This was an experimental feature, so not covered by our deprecation
  117. timeline guarantee.
  118. Features removed for lack of funding
  119. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120. We announced with the 3.1 release that some transports were
  121. moved to experimental status, and that there would be no official
  122. support for the transports, citing a lack of resources.
  123. As this subtle hint for the need of funding failed
  124. we have removed them completely, breaking backwards compatibility.
  125. - Using MongoDB as a broker is no longer supported.
  126. - Using the Django ORM as a broker is no longer supported.
  127. - Using SQLAlchemy as a broker is no longer supported.
  128. - Using CouchDB as a broker is no longer supported.
  129. - Using IronMQ as a broker is no longer supported.
  130. - Using Beanstalk as a broker is no longer supported.
  131. In addition some features have been removed completely so that
  132. attempting to use them will raise an exception:
  133. - The ``--autoreload`` feature has been removed.
  134. This was an experimental feature, and not covered by our deprecation
  135. timeline guarantee. The flag is removed completely so the worker
  136. will crash at startup when present. Luckily this
  137. flag is not used in production systems.
  138. - The ``--autoscale`` feature has been removed.
  139. This flag is only used by companies to save money, but had
  140. bugs either nobody cared to work on, or sponsor a few hours of work to get it fixed.
  141. The flag has been removed completely, so you must remove this command-line
  142. argument or your workers will crash.
  143. - The experimental ``threads`` pool is no longer supported and has been removed.
  144. - The force_execv feature is no longer supported.
  145. The ``celery worker`` command now ignores the ``--no-execv``,
  146. ``--force-execv``, and the ``CELERYD_FORCE_EXECV`` setting.
  147. This flag will be removed completely in 5.0 and the worker
  148. will raise an error.
  149. - The old legacy "amqp" result backend has been deprecated, and will
  150. be removed in Celery 5.0.
  151. Please use the ``rpc`` result backend for RPC-style calls, and a
  152. persistent result backend for multi-consumer results.
  153. **Now to the good news...**
  154. Lowercase setting names
  155. -----------------------
  156. In the pursuit of beauty all settings are now renamed to be in all
  157. lowercase and some setting names have been renamed for consistency.
  158. This change is fully backwards compatible so you can still use the uppercase
  159. setting names, but we would like you to upgrade as soon as possible and
  160. you can this automatically using the :program:`celery upgrade settings`
  161. command:
  162. .. code-block:: console
  163. $ celery upgrade settings proj/settings.py
  164. This command will modify your module in-place to use the new lower-case
  165. names (if you want uppercase with a celery prefix see block below),
  166. and save a backup in :file:`proj/settings.py.orig`.
  167. .. admonition:: For Django users and others who want to keep uppercase names
  168. If you're loading Celery configuration from the Django settings module
  169. then you will want to keep using the uppercase names.
  170. You will also want to use a ``CELERY_`` prefix so that no Celery settings
  171. collide with Django settings used by other apps.
  172. To do this, you will first need to convert your settings file
  173. to use the new consistent naming scheme, and add the prefix to all
  174. Celery related settings:
  175. .. code-block:: console
  176. $ celery upgrade settings --django proj/settings.py
  177. After upgrading the settings file, you need to set the prefix explicitly
  178. in your ``proj/celery.py`` module:
  179. .. code-block:: python
  180. app.config_from_object('django.conf:settings', namespace='CELERY')
  181. You can find the most up to date Django celery integration example
  182. here: :ref:`django-first-steps`.
  183. Note that this will also add a prefix to settings that didn't previously
  184. have one, like ``BROKER_URL``.
  185. Luckily you don't have to manually change the files, as
  186. the :program:`celery upgrade settings --django` program should do the
  187. right thing.
  188. The loader will try to detect if your configuration is using the new format,
  189. and act accordingly, but this also means that you are not allowed to mix and
  190. match new and old setting names, that is unless you provide a value for both
  191. alternatives.
  192. The major difference between previous versions, apart from the lower case
  193. names, are the renaming of some prefixes, like ``celerybeat_`` to ``beat_``,
  194. ``celeryd_`` to ``worker_``.
  195. The ``celery_`` prefix has also been removed, and task related settings
  196. from this name-space is now prefixed by ``task_``, worker related settings
  197. with ``worker_``.
  198. Apart from this most of the settings will be the same in lowercase, apart from
  199. a few special ones:
  200. ===================================== ==========================================================
  201. **Setting name** **Replace with**
  202. ===================================== ==========================================================
  203. ``CELERY_MAX_CACHED_RESULTS`` :setting:`result_cache_max`
  204. ``CELERY_MESSAGE_COMPRESSION`` :setting:`result_compression`/:setting:`task_compression`.
  205. ``CELERY_TASK_RESULT_EXPIRES`` :setting:`result_expires`
  206. ``CELERY_RESULT_DBURI`` :setting:`sqlalchemy_dburi`
  207. ``CELERY_RESULT_ENGINE_OPTIONS`` :setting:`sqlalchemy_engine_options`
  208. ``-*-_DB_SHORT_LIVED_SESSIONS`` :setting:`sqlalchemy_short_lived_sessions`
  209. ``CELERY_RESULT_DB_TABLE_NAMES`` :setting:`sqlalchemy_db_names`
  210. ``CELERY_ACKS_LATE`` :setting:`task_acks_late`
  211. ``CELERY_ALWAYS_EAGER`` :setting:`task_always_eager`
  212. ``CELERY_ANNOTATIONS`` :setting:`task_annotations`
  213. ``CELERY_MESSAGE_COMPRESSION`` :setting:`task_compression`
  214. ``CELERY_CREATE_MISSING_QUEUES`` :setting:`task_create_missing_queues`
  215. ``CELERY_DEFAULT_DELIVERY_MODE`` :setting:`task_default_delivery_mode`
  216. ``CELERY_DEFAULT_EXCHANGE`` :setting:`task_default_exchange`
  217. ``CELERY_DEFAULT_EXCHANGE_TYPE`` :setting:`task_default_exchange_type`
  218. ``CELERY_DEFAULT_QUEUE`` :setting:`task_default_queue`
  219. ``CELERY_DEFAULT_RATE_LIMIT`` :setting:`task_default_rate_limit`
  220. ``CELERY_DEFAULT_ROUTING_KEY`` :setting:`task_default_routing_key`
  221. ``-"-_EAGER_PROPAGATES_EXCEPTIONS`` :setting:`task_eager_propagates`
  222. ``CELERY_IGNORE_RESULT`` :setting:`task_ignore_result`
  223. ``CELERY_TASK_PUBLISH_RETRY`` :setting:`task_publish_retry`
  224. ``CELERY_TASK_PUBLISH_RETRY_POLICY`` :setting:`task_publish_retry_policy`
  225. ``CELERY_QUEUES`` :setting:`task_queues`
  226. ``CELERY_ROUTES`` :setting:`task_routes`
  227. ``CELERY_SEND_TASK_SENT_EVENT`` :setting:`task_send_sent_event`
  228. ``CELERY_TASK_SERIALIZER`` :setting:`task_serializer`
  229. ``CELERYD_TASK_SOFT_TIME_LIMIT`` :setting:`task_soft_time_limit`
  230. ``CELERYD_TASK_TIME_LIMIT`` :setting:`task_time_limit`
  231. ``CELERY_TRACK_STARTED`` :setting:`task_track_started`
  232. ``CELERY_DISABLE_RATE_LIMITS`` :setting:`worker_disable_rate_limits`
  233. ``CELERY_ENABLE_REMOTE_CONTROL`` :setting:`worker_enable_remote_control`
  234. ``CELERYD_SEND_EVENTS`` :setting:`worker_send_task_events`
  235. ===================================== ==========================================================
  236. You can see a full table of the changes in :ref:`conf-old-settings-map`.
  237. JSON is now the default serializer
  238. ----------------------------------
  239. The time has finally come to end the reign of :mod:`pickle` as the default
  240. serialization mechanism, and json is the default serializer starting from this
  241. version.
  242. This change was :ref:`announced with the release of Celery 3.1
  243. <last-version-to-enable-pickle>`.
  244. If you're still depending on :mod:`pickle` being the default serializer,
  245. then you have to configure your app before upgrading to 4.0:
  246. .. code-block:: python
  247. task_serializer = 'pickle'
  248. result_serializer = 'pickle'
  249. accept_content = {'pickle'}
  250. The Task base class no longer automatically register tasks
  251. ----------------------------------------------------------
  252. The :class:`~@Task` class is no longer using a special meta-class
  253. that automatically registers the task in the task registry.
  254. Instead this is now handled by the :class:`@task` decorators.
  255. If you're still using class based tasks, then you need to register
  256. these manually:
  257. .. code-block:: python
  258. class CustomTask(Task):
  259. def run(self):
  260. print('running')
  261. app.tasks.register(CustomTask())
  262. The best practice is to use custom task classes only for overriding
  263. general behavior, and then using the task decorator to realize the task:
  264. .. code-block:: python
  265. @app.task(bind=True, base=CustomTask)
  266. def custom(self):
  267. print('running')
  268. This change also means the ``abstract`` attribute of the task
  269. no longer has any effect.
  270. Task argument checking
  271. ----------------------
  272. The arguments of the task are now verified when calling the task,
  273. even asynchronously:
  274. .. code-block:: pycon
  275. >>> @app.task
  276. ... def add(x, y):
  277. ... return x + y
  278. >>> add.delay(8, 8)
  279. <AsyncResult: f59d71ca-1549-43e0-be41-4e8821a83c0c>
  280. >>> add.delay(8)
  281. Traceback (most recent call last):
  282. File "<stdin>", line 1, in <module>
  283. File "celery/app/task.py", line 376, in delay
  284. return self.apply_async(args, kwargs)
  285. File "celery/app/task.py", line 485, in apply_async
  286. check_arguments(*(args or ()), **(kwargs or {}))
  287. TypeError: add() takes exactly 2 arguments (1 given)
  288. Redis Events not backward compatible
  289. ------------------------------------
  290. The Redis ``fanout_patterns`` and ``fanout_prefix`` transport
  291. options are now enabled by default.
  292. Workers/monitors without these flags enabled will not be able to
  293. see workers with this flag disabled. They can still execute tasks,
  294. but they cannot receive each others monitoring messages.
  295. You can upgrade in a backward compatible manner by first configuring
  296. your 3.1 workers and monitors to enable the settings, before the final
  297. upgrade to 4.0:
  298. .. code-block:: python
  299. BROKER_TRANSPORT_OPTIONS = {
  300. 'fanout_patterns': True,
  301. 'fanout_prefix': True,
  302. }
  303. Django: Auto-discover now supports Django app configurations
  304. ------------------------------------------------------------
  305. The :meth:`@autodiscover` function can now be called without arguments,
  306. and the Django handler will automatically find your installed apps:
  307. .. code-block:: python
  308. app.autodiscover()
  309. The Django integration :ref:`example in the documentation
  310. <django-first-steps>` has been updated to use the argument-less call.
  311. This also ensures comaptibility with the new, ehm, ``appconfig`` stuff
  312. introduced in recent Django versions.
  313. Worker direct queues no longer use auto-delete.
  314. -----------------------------------------------
  315. Workers/clients running 4.0 will no longer be able to send
  316. worker direct messages to workers running older versions, and vice versa.
  317. If you're relying on worker direct messages you should upgrade
  318. your 3.x workers and clients to use the new routing settings first,
  319. by replacing :func:`celery.utils.worker_direct` with this implementation:
  320. .. code-block:: python
  321. from kombu import Exchange, Queue
  322. worker_direct_exchange = Exchange('C.dq2')
  323. def worker_direct(hostname):
  324. return Queue(
  325. '{hostname}.dq2'.format(hostname),
  326. exchange=worker_direct_exchange,
  327. routing_key=hostname,
  328. )
  329. (This feature closed Issue #2492.)
  330. Old command-line programs removed
  331. ---------------------------------
  332. Installing Celery will no longer install the ``celeryd``,
  333. ``celerybeat`` and ``celeryd-multi`` programs.
  334. This was announced with the release of Celery 3.1, but you may still
  335. have scripts pointing to the old names so make sure you update these
  336. to use the new umbrella command:
  337. +-------------------+--------------+-------------------------------------+
  338. | Program | New Status | Replacement |
  339. +===================+==============+=====================================+
  340. | ``celeryd`` | **REMOVED** | :program:`celery worker` |
  341. +-------------------+--------------+-------------------------------------+
  342. | ``celerybeat`` | **REMOVED** | :program:`celery beat` |
  343. +-------------------+--------------+-------------------------------------+
  344. | ``celeryd-multi`` | **REMOVED** | :program:`celery multi` |
  345. +-------------------+--------------+-------------------------------------+
  346. .. _v400-news:
  347. News
  348. ====
  349. New Task Message Protocol
  350. -------------------------
  351. .. :sha:`e71652d384b1b5df2a4e6145df9f0efb456bc71c`
  352. This version introduces a brand new task message protocol,
  353. the first major change to the protocol since the beginning of the project.
  354. The new protocol is backwards incompatible, so you need to set
  355. the :setting:`task_protocol` configuration option to ``2`` to take advantage:
  356. .. code-block:: python
  357. app = Celery()
  358. app.conf.task_protocol = 2
  359. Using the new protocol is recommended for everybody who don't
  360. need backwards compatibility.
  361. Once enabled task messages sent is unreadable to older versions of Celery.
  362. New protocol highlights
  363. ~~~~~~~~~~~~~~~~~~~~~~~
  364. The new protocol fixes many problems with the old one, and enables
  365. some long-requested features:
  366. - Most of the data are now sent as message headers, instead of being
  367. serialized with the message body.
  368. In version 1 of the protocol the worker always had to deserialize
  369. the message to be able to read task meta-data like the task id,
  370. name, etc. This also meant that the worker was forced to double-decode
  371. the data, first deserializing the message on receipt, serializing
  372. the message again to send to child process, then finally the child process
  373. deserializes the message again.
  374. Keeping the meta-data fields in the message headers means the worker
  375. does not actually have to decode the payload before delivering
  376. the task to the child process, and also that it's now possible
  377. for the worker to reroute a task written in a language different
  378. from Python to a different worker.
  379. - A new ``lang`` message header can be used to specify the programming
  380. language the task is written in.
  381. - Worker stores results for internal errors like ``ContentDisallowed``,
  382. and other deserialization errors.
  383. - Worker stores results and sends monitoring events for unregistered
  384. task errors.
  385. - Worker calls callbacks/errbacks even when the result is sent by the
  386. parent process (e.g. :exc:`WorkerLostError` when a child process
  387. terminates, deserialization errors, unregistered tasks).
  388. - A new ``origin`` header contains information about the process sending
  389. the task (worker node-name, or PID and host-name information).
  390. - A new ``shadow`` header allows you to modify the task name used in logs.
  391. This is useful for dispatch like patterns, like a task that calls
  392. any function using pickle (don't do this at home):
  393. .. code-block:: python
  394. from celery import Task
  395. from celery.utils.imports import qualname
  396. class call_as_task(Task):
  397. def shadow_name(self, args, kwargs, options):
  398. return 'call_as_task:{0}'.format(qualname(args[0]))
  399. def run(self, fun, *args, **kwargs):
  400. return fun(*args, **kwargs)
  401. call_as_task = app.tasks.register(call_as_task())
  402. - New ``argsrepr`` and ``kwargsrepr`` fields contain textual representations
  403. of the task arguments (possibly truncated) for use in logs, monitors, etc.
  404. This means the worker does not have to deserialize the message payload
  405. to display the task arguments for informational purposes.
  406. - Chains now use a dedicated ``chain`` field enabling support for chains
  407. of thousands and more tasks.
  408. - New ``parent_id`` and ``root_id`` headers adds information about
  409. a tasks relationship with other tasks.
  410. - ``parent_id`` is the task id of the task that called this task
  411. - ``root_id`` is the first task in the work-flow.
  412. These fields can be used to improve monitors like flower to group
  413. related messages together (like chains, groups, chords, complete
  414. work-flows, etc).
  415. - ``app.TaskProducer`` replaced by :meth:`@amqp.create_task_message`` and
  416. :meth:`@amqp.send_task_message``.
  417. Dividing the responsibilities into creating and sending means that
  418. people who want to send messages using a Python AMQP client directly,
  419. does not have to implement the protocol.
  420. The :meth:`@amqp.create_task_message` method calls either
  421. :meth:`@amqp.as_task_v2`, or :meth:`@amqp.as_task_v1` depending
  422. on the configured task protocol, and returns a special
  423. :class:`~celery.app.amqp.task_message` tuple containing the
  424. headers, properties and body of the task message.
  425. .. seealso::
  426. The new task protocol is documented in full here:
  427. :ref:`message-protocol-task-v2`.
  428. Prefork: Tasks now log from the child process
  429. ---------------------------------------------
  430. Logging of task success/failure now happens from the child process
  431. actually executing the task, which means that logging utilities
  432. like Sentry can get full information about tasks that fail, including
  433. variables in the traceback.
  434. Prefork: One log-file per child process
  435. ---------------------------------------
  436. Init-scrips and :program:`celery multi` now uses the `%I` log file format
  437. option (e.g. :file:`/var/log/celery/%n%I.log`).
  438. This change was necessary to ensure each child
  439. process has a separate log file after moving task logging
  440. to the child process, as multiple processes writing to the same
  441. log file can cause corruption.
  442. You are encouraged to upgrade your init-scripts and
  443. :program:`celery multi` arguments to use this new option.
  444. Configure broker URL for read/write separately.
  445. -----------------------------------------------
  446. New :setting:`broker_read_url` and :setting:`broker_write_url` settings
  447. have been added so that separate broker URLs can be provided
  448. for connections used for consuming/publishing.
  449. In addition to the configuration options, two new methods have been
  450. added the app API:
  451. - ``app.connection_for_read()``
  452. - ``app.connection_for_write()``
  453. These should now be used in place of ``app.connection()`` to specify
  454. the intent of the required connection.
  455. .. note::
  456. Two connection pools are available: ``app.pool`` (read), and
  457. ``app.producer_pool`` (write). The latter does not actually give connections
  458. but full :class:`kombu.Producer` instances.
  459. .. code-block:: python
  460. def publish_some_message(app, producer=None):
  461. with app.producer_or_acquire(producer) as producer:
  462. ...
  463. def consume_messages(app, connection=None):
  464. with app.connection_or_acquire(connection) as connection:
  465. ...
  466. Canvas Refactor
  467. ---------------
  468. The canvas/work-flow implementation have been heavily refactored
  469. to fix some long outstanding issues.
  470. .. :sha:`d79dcd8e82c5e41f39abd07ffed81ca58052bcd2`
  471. .. :sha:`1e9dd26592eb2b93f1cb16deb771cfc65ab79612`
  472. .. :sha:`e442df61b2ff1fe855881c1e2ff9acc970090f54`
  473. .. :sha:`0673da5c09ac22bdd49ba811c470b73a036ee776`
  474. - Error callbacks can now take real exception and traceback instances
  475. (Issue #2538).
  476. .. code-block:: pycon
  477. >>> add.s(2, 2).on_error(log_error.s()).delay()
  478. Where ``log_error`` could be defined as:
  479. .. code-block:: python
  480. @app.task
  481. def log_error(request, exc, traceback):
  482. with open(os.path.join('/var/errors', request.id), 'a') as fh:
  483. print('--\n\n{0} {1} {2}'.format(
  484. task_id, exc, traceback), file=fh)
  485. See :ref:`guide-canvas` for more examples.
  486. - Now unrolls groups within groups into a single group (Issue #1509).
  487. - chunks/map/starmap tasks now routes based on the target task
  488. - chords and chains can now be immutable.
  489. - Fixed bug where serialized signatures were not converted back into
  490. signatures (Issue #2078)
  491. Fix contributed by **Ross Deane**.
  492. - Fixed problem where chains and groups did not work when using JSON
  493. serialization (Issue #2076).
  494. Fix contributed by **Ross Deane**.
  495. - Creating a chord no longer results in multiple values for keyword
  496. argument 'task_id' (Issue #2225).
  497. Fix contributed by **Aneil Mallavarapu**.
  498. - Fixed issue where the wrong result is returned when a chain
  499. contains a chord as the penultimate task.
  500. Fix contributed by **Aneil Mallavarapu**.
  501. - Special case of ``group(A.s() | group(B.s() | C.s()))`` now works.
  502. - Chain: Fixed bug with incorrect id set when a subtask is also a chain.
  503. - ``group | group`` is now flattened into a single group (Issue #2573).
  504. - Fixed issue where ``group | task`` was not upgrading correctly
  505. to chord (Issue #2922).
  506. Amazon SQS transport now officially supported.
  507. ----------------------------------------------
  508. The SQS broker transport has been rewritten to use async I/O and as such
  509. joins RabbitMQ and Redis as officially supported transports.
  510. The new implementation also takes advantage of long polling,
  511. and closes several issues related to using SQS as a broker.
  512. This work was sponsored by Nextdoor.
  513. Apache QPid transport now officially supported.
  514. -----------------------------------------------
  515. Contributed by **Brian Bouterse**.
  516. Schedule tasks based on sunrise, sunset, dawn and dusk.
  517. -------------------------------------------------------
  518. See :ref:`beat-solar` for more information.
  519. Contributed by **Mark Parncutt**.
  520. New API for configuring periodic tasks
  521. --------------------------------------
  522. This new API enables you to use signatures when defining periodic tasks,
  523. removing the chance of mistyping task names.
  524. An example of the new API is :ref:`here <beat-entries>`.
  525. .. :sha:`bc18d0859c1570f5eb59f5a969d1d32c63af764b`
  526. .. :sha:`132d8d94d38f4050db876f56a841d5a5e487b25b`
  527. RabbitMQ Priority queue support
  528. -------------------------------
  529. See :ref:`routing-options-rabbitmq-priorities` for more information.
  530. Contributed by **Gerald Manipon**.
  531. Prefork: Limit child process resident memory size.
  532. --------------------------------------------------
  533. .. :sha:`5cae0e754128750a893524dcba4ae030c414de33`
  534. You can now limit the maximum amount of memory allocated per prefork
  535. pool child process by setting the worker
  536. :option:`--maxmemperchild <celery worker --maxmemperchild>` option,
  537. or the :setting:`worker_max_memory_per_child` setting.
  538. The limit is for RSS/resident memory size and is specified in kilobytes.
  539. A child process having exceeded the limit will be terminated and replaced
  540. with a new process after the currently executing task returns.
  541. See :ref:`worker-maxmemperchild` for more information.
  542. Contributed by **Dave Smith**.
  543. Redis: Result backend optimizations
  544. -----------------------------------
  545. RPC is now using pub/sub for streaming task results.
  546. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  547. Calling ``result.get()`` when using the Redis result backend
  548. used to be extremely expensive as it was using polling to wait
  549. for the result to become available. A default polling
  550. interval of 0.5 seconds did not help performance, but was
  551. necessary to avoid a spin loop.
  552. The new implementation is using Redis Pub/Sub mechanisms to
  553. publish and retrieve results immediately, greatly improving
  554. task round-trip times.
  555. Contributed by **Yaroslav Zhavoronkov** and **Ask Solem**.
  556. New optimized chord join implementation.
  557. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  558. This was an experimental feature introduced in Celery 3.1,
  559. that could only be enabled by adding ``?new_join=1`` to the
  560. result backend URL configuration.
  561. We feel that the implementation has been tested thoroughly enough
  562. to be considered stable and enabled by default.
  563. The new implementation greatly reduces the overhead of chords,
  564. and especially with larger chords the performance benefit can be massive.
  565. New Riak result backend Introduced.
  566. -----------------------------------
  567. See :ref:`conf-riak-result-backend` for more information.
  568. Contributed by **Gilles Dartiguelongue**, **Alman One** and **NoKriK**.
  569. New CouchDB result backend introduced.
  570. --------------------------------------
  571. See :ref:`conf-couchdb-result-backend` for more information.
  572. Contributed by **Nathan Van Gheem**.
  573. New Consul result backend introduced.
  574. -------------------------------------
  575. Add support for Consul as a backend using the Key/Value store of Consul.
  576. Consul has a HTTP API where through you can store keys with their values.
  577. The backend extends KeyValueStoreBackend and implements most of the methods.
  578. Mainly to set, get and remove objects.
  579. This allows Celery to store Task results in the K/V store of Consul.
  580. Consul also allows to set a TTL on keys using the Sessions from Consul. This way
  581. the backend supports auto expiry of Task results.
  582. For more information on Consul visit http://consul.io/
  583. The backend uses python-consul for talking to the HTTP API. This package is fully
  584. Python 3 compliant just as this backend is:
  585. .. code-block:: console
  586. $ pip install python-consul
  587. That installs the required package to talk to Consul's HTTP API from Python.
  588. Contributed by **Wido den Hollander**.
  589. Brand new Cassandra result backend.
  590. -----------------------------------
  591. A brand new Cassandra backend utilizing the new :pypi:`cassandra-driver`
  592. library is replacing the old result backend which was using the older
  593. :pypi:`pycassa` library.
  594. See :ref:`conf-cassandra-result-backend` for more information.
  595. .. # XXX What changed?
  596. New Elasticsearch result backend introduced.
  597. --------------------------------------------
  598. See :ref:`conf-elasticsearch-result-backend` for more information.
  599. Contributed by **Ahmet Demir**.
  600. New File-system result backend introduced.
  601. ------------------------------------------
  602. See :ref:`conf-filesystem-result-backend` for more information.
  603. Contributed by **Môshe van der Sterre**.
  604. Event Batching
  605. --------------
  606. Events are now buffered in the worker and sent as a list which reduces
  607. the overhead required to send monitoring events.
  608. For authors of custom event monitors there will be no action
  609. required as long as you're using the Python celery
  610. helpers (:class:`~@events.Receiver`) to implement your monitor.
  611. However, if you're manually receiving event messages you must now account
  612. for batched event messages which differ from normal event messages
  613. in the following way:
  614. - The routing key for a batch of event messages will be set to
  615. ``<event-group>.multi`` where the only batched event group
  616. is currently ``task`` (giving a routing key of ``task.multi``).
  617. - The message body will be a serialized list-of-dictionaries instead
  618. of a dictionary. Each item in the list can be regarded
  619. as a normal event message body.
  620. .. :sha:`03399b4d7c26fb593e61acf34f111b66b340ba4e`
  621. Task.replace
  622. ------------
  623. Task.replace changed, removes Task.replace_in_chord.
  624. The two methods had almost the same functionality, but the old
  625. ``Task.replace`` would force the new task to inherit the
  626. callbacks/errbacks of the existing task.
  627. If you replace a node in a tree, then you would not expect the new node to
  628. inherit the children of the old node, so this seems like unexpected
  629. behavior.
  630. So ``self.replace(sig)`` now works for any task, in addition ``sig`` can now
  631. be a group.
  632. Groups are automatically converted to a chord, where the callback
  633. will "accumulate" the results of the group tasks.
  634. A new built-in task (`celery.accumulate` was added for this purpose)
  635. Closes #817
  636. Optimized Beat implementation
  637. -----------------------------
  638. The :program:`celery beat` implementation has been optimized
  639. for millions of periodic tasks by using a heap to schedule entries.
  640. Contributed by **Ask Solem** and **Alexander Koshelev**.
  641. Task Auto-retry Decorator
  642. -------------------------
  643. Writing custom retry handling for exception events is so common
  644. that we now have built-in support for it.
  645. For this a new ``autoretry_for`` argument is now supported by
  646. the task decorators, where you can specify a tuple of exceptions
  647. to automatically retry for.
  648. See :ref:`task-autoretry` for more information.
  649. Contributed by **Dmitry Malinovsky**.
  650. .. :sha:`75246714dd11e6c463b9dc67f4311690643bff24`
  651. Remote Task Tracebacks
  652. ----------------------
  653. The new :setting:`task_remote_tracebacks` will make task tracebacks more
  654. useful by injecting the stack of the remote worker.
  655. This feature requires the additional :pypi:`tblib` library.
  656. Contributed by **Ionel Cristian Mărieș**.
  657. Async Result API
  658. ----------------
  659. eventlet/gevent drainers, promises, BLA BLA
  660. Closed issue #2529.
  661. RPC Result Backend matured.
  662. ---------------------------
  663. Lots of bugs in the previously experimental RPC result backend have been fixed
  664. and we now consider it production ready.
  665. Contributed by **Ask Solem**, **Morris Tweed**.
  666. New Task Router API
  667. -------------------
  668. The :setting:`task_routes` setting can now hold functions, and map routes
  669. now support glob patterns and regexes.
  670. Instead of using router classes you can now simply define a function:
  671. .. code-block:: python
  672. def route_for_task(name, args, kwargs, options, task=None, **kwargs):
  673. from proj import tasks
  674. if name == tasks.add.name:
  675. return {'queue': 'hipri'}
  676. If you don't need the arguments you can use start arguments, just make
  677. sure you always also accept star arguments so that we have the ability
  678. to add more features in the future:
  679. .. code-block:: python
  680. def route_for_task(name, *args, **kwargs):
  681. from proj import tasks
  682. if name == tasks.add.name:
  683. return {'queue': 'hipri', 'priority': 9}
  684. Both the ``options`` argument and the new ``task`` keyword argument
  685. are new to the function-style routers, and will make it easier to write
  686. routers based on execution options, or properties of the task.
  687. The optional ``task`` keyword argument will not be set if a task is called
  688. by name using :meth:`@send_task`.
  689. For more examples, including using glob/regexes in routers please see
  690. :setting:`task_routes` and :ref:`routing-automatic`.
  691. In Other News
  692. -------------
  693. Requirements
  694. ~~~~~~~~~~~~
  695. - Now depends on :ref:`Kombu 4.0 <kombu:version-4.0>`.
  696. - Now depends on :pypi:`billiard` version 3.5.
  697. - No longer depends on :pypi:`anyjson`. Good-bye old friend :(
  698. Tasks
  699. ~~~~~
  700. - The "anon-exchange" is now used for simple name-name direct routing.
  701. This increases performance as it completely bypasses the routing table,
  702. in addition it also improves reliability for the Redis broker transport.
  703. - An empty ResultSet now evaluates to True.
  704. Fix contributed by **Colin McIntosh**.
  705. - New :setting:`task_reject_on_worker_lost` setting, and
  706. :attr:`~@Task.reject_on_worker_lost` task attribute decides what happens
  707. when the child worker process executing a late ack task is terminated.
  708. Contributed by **Michael Permana**.
  709. - ``Task.subtask`` renamed to ``Task.signature`` with alias.
  710. - ``Task.subtask_from_request`` renamed to
  711. ``Task.signature_from_request`` with alias.
  712. - The ``delivery_mode`` attribute for :class:`kombu.Queue` is now
  713. respected (Issue #1953).
  714. - Routes in :setting:`task-routes` can now specify a
  715. :class:`~kombu.Queue` instance directly.
  716. Example:
  717. .. code-block:: python
  718. task_routes = {'proj.tasks.add': {'queue': Queue('add')}}
  719. - ``AsyncResult`` now raises :exc:`ValueError` if task_id is None.
  720. (Issue #1996).
  721. - Retried tasks did not forward expires setting (Issue #3297).
  722. - ``result.get()`` now supports an ``on_message`` argument to set a
  723. callback to be called for every message received.
  724. - New abstract classes added:
  725. - :class:`~celery.utils.abstract.CallableTask`
  726. Looks like a task.
  727. - :class:`~celery.utils.abstract.CallableSignature`
  728. Looks like a task signature.
  729. - ``Task.replace`` now properly forwards callbacks (Issue #2722).
  730. Fix contributed by **Nicolas Unravel**.
  731. - ``Task.replace``: Append to chain/chord (Closes #3232)
  732. Fixed issue #3232, adding the signature to the chain (if there is any).
  733. Fixed the chord suppress if the given signature contains one.
  734. Fix contributed by :github_user:`honux`.
  735. - Task retry now also throws in eager mode.
  736. Fix contributed by **Feanil Patel**.
  737. Beat
  738. ~~~~
  739. - Fixed crontab infinite loop with invalid date.
  740. When occurrence can never be reached (example, April, 31th), trying
  741. to reach the next occurrence would trigger an infinite loop.
  742. Try fixing that by raising a RuntimeError after 2,000 iterations
  743. (Also added a test for crontab leap years in the process)
  744. Fix contributed by **Romuald Brunet**.
  745. - Now ensures the program exits with a non-zero exit code when an
  746. exception terminates the service.
  747. Fix contributed by **Simon Peeters**.
  748. App
  749. ~~~
  750. - Dates are now always timezone aware even if
  751. :setting:`enable_utc` is disabled (Issue #943).
  752. Fix contributed by **Omer Katz**.
  753. - **Config**: App preconfiguration is now also pickled with the configuration.
  754. Fix contributed by **Jeremy Zafran**.
  755. - The application can now change how task names are generated using
  756. the :meth:`~@gen_task_name` method.
  757. Contributed by **Dmitry Malinovsky**.
  758. - App has new ``app.current_worker_task`` property that
  759. returns the task that is currently being worked on (or :const:`None`).
  760. (Issue #2100).
  761. Execution Pools
  762. ~~~~~~~~~~~~~~~
  763. - **Eventlet/Gevent**: Fixed race condition leading to "simultaneous read"
  764. errors (Issue #2812).
  765. - **Prefork**: Prefork pool now uses ``poll`` instead of ``select`` where
  766. available (Issue #2373).
  767. - **Prefork**: Fixed bug where the pool would refuse to shut down the
  768. worker (Issue #2606).
  769. - **Eventlet**: Now returns pool size in :program:`celery inspect stats`
  770. command.
  771. Contributed by **Alexander Oblovatniy**.
  772. Transports
  773. ~~~~~~~~~~
  774. - **Redis Transport**: The Redis transport now supports the
  775. :setting:`broker_use_ssl` option.
  776. Programs
  777. ~~~~~~~~
  778. - :program:`celery multi`: ``%n`` format for is now synonym with
  779. ``%N`` to be consistent with :program:`celery worker`.
  780. - :program:`celery inspect`/:program:`celery control`: now supports a new
  781. :option:`--json <celery inspect --json>` option to give output in json format.
  782. - :program:`celery inspect registered`: now ignores built-in tasks.
  783. - :program:`celery purge` now takes ``-Q`` and ``-X`` options
  784. used to specify which queues to include and exclude from the purge.
  785. - New :program:`celery logtool`: Utility for filtering and parsing
  786. celery worker log-files
  787. - :program:`celery multi`: now passes through `%i` and `%I` log
  788. file formats.
  789. - General: ``%p`` can now be used to expand to the full worker node-name
  790. in log-file/pid-file arguments.
  791. - A new command line option
  792. :option:`--executable <celery worker --executable>` is now
  793. available for daemonizing programs (:program:`celery worker` and
  794. :program:`celery beat`).
  795. Contributed by **Bert Vanderbauwhede**.
  796. - :program:`celery worker`: supports new
  797. :option:`--prefetch-multiplier <celery worker --prefetch-multiplier>` option.
  798. Contributed by **Mickaël Penhard**.
  799. Worker
  800. ~~~~~~
  801. - Improvements and fixes for :class:`~celery.utils.collections.LimitedSet`.
  802. Getting rid of leaking memory + adding ``minlen`` size of the set:
  803. the minimal residual size of the set after operating for some time.
  804. ``minlen`` items are kept, even if they should have been expired.
  805. Problems with older and even more old code:
  806. #. Heap would tend to grow in some scenarios
  807. (like adding an item multiple times).
  808. #. Adding many items fast would not clean them soon enough (if ever).
  809. #. When talking to other workers, revoked._data was sent, but
  810. it was processed on the other side as iterable.
  811. That means giving those keys new (current)
  812. time-stamp. By doing this workers could recycle
  813. items forever. Combined with 1) and 2), this means that in
  814. large set of workers, you are getting out of memory soon.
  815. All those problems should be fixed now.
  816. This should fix issues #3095, #3086.
  817. Contributed by **David Pravec**.
  818. - Worker now only starts the remote control command consumer if the
  819. broker transport used actually supports them.
  820. - Gossip now sets ``x-message-ttl`` for event queue to heartbeat_interval s.
  821. (Issue #2005).
  822. - Now preserves exit code (Issue #2024).
  823. - Fixed crash when the ``-purge`` argument was used.
  824. - Log--level for unrecoverable errors changed from ``error`` to
  825. ``critical``.
  826. - Improved rate limiting accuracy.
  827. - Account for missing timezone information in task expires field.
  828. Fix contributed by **Albert Wang**.
  829. - The worker no longer has a ``Queues`` bootsteps, as it is now
  830. superfluous.
  831. - Now emits the "Received task" line even for revoked tasks.
  832. (Issue #3155).
  833. - Now respects :setting:`broker_connection_retry` setting.
  834. Fix contributed by **Nat Williams**.
  835. - New :data:`celery.worker.state.requests` enables O(1) loookup
  836. of active/reserved tasks by id.
  837. - Auto-scale did not always update keep-alive when scaling down.
  838. Fix contributed by **Philip Garnero**.
  839. - Fixed typo ``options_list`` -> ``option_list``.
  840. Fix contributed by **Greg Wilbur**.
  841. Debugging Utilities
  842. ~~~~~~~~~~~~~~~~~~~
  843. - :mod:`celery.contrib.rdb`: Changed remote debugger banner so that you can copy and paste
  844. the address easily (no longer has a period in the address).
  845. Contributed by **Jonathan Vanasco**.
  846. - Fixed compatibility with recent :pypi:`psutil` versions (Issue #3262).
  847. Signals
  848. ~~~~~~~
  849. - **App**: New signals for app configuration/finalization:
  850. - :data:`app.on_configure <@on_configure>`
  851. - :data:`app.on_after_configure <@on_after_configure>`
  852. - :data:`app.on_after_finalize <@on_after_finalize>`
  853. - **Task**: New task signals for rejected task messages:
  854. - :data:`celery.signals.task_rejected`.
  855. - :data:`celery.signals.task_unknown`.
  856. - **Worker**: New signal for when a heartbeat event is sent.
  857. - :data:`celery.signals.heartbeat_sent`
  858. Contributed by **Kevin Richardson**.
  859. Events
  860. ~~~~~~
  861. - Event messages now uses the RabbitMQ ``x-message-ttl`` option
  862. to ensure older event messages are discarded.
  863. The default is 5 seconds, but can be changed using the
  864. :setting:`event_queue_ttl` setting.
  865. - Event monitors now sets the :setting:`event_queue_expires`
  866. setting by default.
  867. The queues will now expire after 60 seconds after the monitor stops
  868. consuming from it.
  869. - Fixed a bug where a None value was not handled properly.
  870. Fix contributed by **Dongweiming**.
  871. - New :setting:`event_queue_prefix` setting can now be used
  872. to change the default ``celeryev`` queue prefix for event receiver queues.
  873. Contributed by **Takeshi Kanemoto**.
  874. - ``State.tasks_by_type`` and ``State.tasks_by_worker`` can now be
  875. used as a mapping for fast access to this information.
  876. Canvas
  877. ~~~~~~
  878. - ``chunks``/``map``/``starmap`` are now routed based on the target task.
  879. - ``Signature.link`` now works when argument is scalar (not a list)
  880. (Issue #2019).
  881. Deployment
  882. ~~~~~~~~~~
  883. - Generic init-scripts now support
  884. :envvar:`CELERY_SU`` and :envvar:`CELERYD_SU_ARGS` environment variables
  885. to set the path and arguments for :command:`su` (:manpage:`su(1)`).
  886. - Generic init-scripts now better support FreBSD and other BSD
  887. systems by searching :file:`/usr/local/etc/` for the configuration file.
  888. Contributed by **Taha Jahangir**.
  889. - Generic init-script: Fixed strange bug for ``celerybeat`` where
  890. restart did not always work (Issue #3018).
  891. - The systemd init script now uses a shell when executing
  892. services.
  893. Contributed by **Tomas Machalek**.
  894. Result Backends
  895. ~~~~~~~~~~~~~~~
  896. - Redis: Now has a default socket timeout of 5 seconds.
  897. The default can be changed using the new :setting:`redis_socket_timeout`
  898. setting.
  899. Contributed by **Raghuram Srinivasan**.
  900. - RPC Backend result queues are now auto delete by default (Issue #2001).
  901. - RPC Backend: Fixed problem where exception
  902. was not deserialized properly with the json serializer (Issue #2518).
  903. Fix contributed by **Allard Hoeve**.
  904. - CouchDB: Fixed typo causing the backend to not be found
  905. (Issue #3287).
  906. Fix contributed by **Andrew Stewart**.
  907. - MongoDB: Now supports setting the :setting:`result_serialzier` setting
  908. to ``bson`` to use the MongoDB libraries own serializer.
  909. Contributed by **Davide Quarta**.
  910. - MongoDB: URI handling has been improved to use
  911. database name, user and password from the URI if provided.
  912. Contributed by **Samuel Jaillet**.
  913. - SQLAlchemy result backend: Now ignores all result
  914. engine options when using NullPool (Issue #1930).
  915. - SQLAlchemy result backend: Now sets max char size to 155 to deal
  916. with brain damaged MySQL unicode implementation (Issue #1748).
  917. - **General**: All Celery exceptions/warnings now inherit from common
  918. :class:`~celery.exceptions.CeleryException`/:class:`~celery.exceptions.CeleryWarning`.
  919. (Issue #2643).
  920. Documentation Improvements
  921. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  922. Contributed by:
  923. - Adam Chainz
  924. - Arthur Vuillard
  925. - Batiste Bieler
  926. - Daniel Devine
  927. - Edward Betts
  928. - Jason Veatch
  929. - Jeff Widman
  930. - Manuel Kaufmann
  931. - Maxime Beauchemin
  932. - Mitchel Humpherys
  933. - Rik
  934. - Tayfun Sen
  935. Reorganization, Deprecations, and Removals
  936. ==========================================
  937. Incompatible changes
  938. --------------------
  939. - Prefork: Calling ``result.get()`` or joining any result from within a task
  940. now raises :exc:`RuntimeError`.
  941. In previous versions this would emit a warning.
  942. - :mod:`celery.worker.consumer` is now a package, not a module.
  943. - Module ``celery.worker.job`` renamed to :mod:`celery.worker.request`.
  944. - Beat: ``Scheduler.Publisher``/``.publisher`` renamed to
  945. ``.Producer``/``.producer``.
  946. - Result: The task_name argument/attribute of :class:`@AsyncResult` was
  947. removed.
  948. This was historically a field used for :mod:`pickle` compatibility,
  949. but is no longer needed.
  950. - Backends: Arguments named ``status`` renamed to ``state``.
  951. - Backends: ``backend.get_status()`` renamed to ``backend.get_state()``.
  952. .. _v400-unscheduled-removals:
  953. Unscheduled Removals
  954. --------------------
  955. - The experimental :mod:`celery.contrib.methods` feature has been removed,
  956. as there were far many bugs in the implementation to be useful.
  957. - The CentOS init-scripts have been removed.
  958. These did not really add any features over the generic init-scripts,
  959. so you are encouraged to use them instead, or something like
  960. :pypi:`supervisor`.
  961. .. _v400-deprecations-reorg:
  962. Reorganization Deprecations
  963. ---------------------------
  964. These symbols have been renamed, and while there is an alias available in this
  965. version for backward compatibility, they will be removed in Celery 5.0, so
  966. make sure you rename these ASAP to make sure it won't break for that release.
  967. Chances are that you will only use the first in this list, but you never
  968. know:
  969. - ``celery.utils.worker_direct`` ->
  970. :meth:`celery.utils.nodenames.worker_direct`.
  971. - ``celery.utils.nodename`` -> :meth:`celery.utils.nodenames.nodename`.
  972. - ``celery.utils.anon_nodename`` ->
  973. :meth:`celery.utils.nodenames.anon_nodename`.
  974. - ``celery.utils.nodesplit`` -> :meth:`celery.utils.nodenames.nodesplit`.
  975. - ``celery.utils.default_nodename`` ->
  976. :meth:`celery.utils.nodenames.default_nodename`.
  977. - ``celery.utils.node_format`` -> :meth:`celery.utils.nodenames.node_format`.
  978. - ``celery.utils.host_format`` -> :meth:`celery.utils.nodenames.host_format`.
  979. .. _v400-removals:
  980. Scheduled Removals
  981. ------------------
  982. Modules
  983. ~~~~~~~
  984. - Module ``celery.worker.job`` has been renamed to :mod:`celery.worker.request`.
  985. This was an internal module so should not have any effect.
  986. It is now part of the public API so should not change again.
  987. - Module ``celery.task.trace`` has been renamed to ``celery.app.trace``
  988. as the ``celery.task`` package is being phased out. The module
  989. will be removed in version 5.0 so please change any import from::
  990. from celery.task.trace import X
  991. to::
  992. from celery.app.trace import X
  993. - Old compatibility aliases in the :mod:`celery.loaders` module
  994. has been removed.
  995. - Removed ``celery.loaders.current_loader()``, use: ``current_app.loader``
  996. - Removed ``celery.loaders.load_settings()``, use: ``current_app.conf``
  997. Result
  998. ~~~~~~
  999. - ``AsyncResult.serializable()`` and ``celery.result.from_serializable``
  1000. has been removed:
  1001. Use instead:
  1002. .. code-block:: pycon
  1003. >>> tup = result.as_tuple()
  1004. >>> from celery.result import result_from_tuple
  1005. >>> result = result_from_tuple(tup)
  1006. - Removed ``BaseAsyncResult``, use ``AsyncResult`` for instance checks
  1007. instead.
  1008. - Removed ``TaskSetResult``, use ``GroupResult`` instead.
  1009. - ``TaskSetResult.total`` -> ``len(GroupResult)``
  1010. - ``TaskSetResult.taskset_id`` -> ``GroupResult.id``
  1011. - Removed ``ResultSet.subtasks``, use ``ResultSet.results`` instead.
  1012. TaskSet
  1013. ~~~~~~~
  1014. TaskSet has been renamed to group and TaskSet will be removed in version 4.0.
  1015. Old::
  1016. >>> from celery.task import TaskSet
  1017. >>> TaskSet(add.subtask((i, i)) for i in xrange(10)).apply_async()
  1018. New::
  1019. >>> from celery import group
  1020. >>> group(add.s(i, i) for i in xrange(10))()
  1021. Events
  1022. ~~~~~~
  1023. - Removals for class :class:`celery.events.state.Worker`:
  1024. - ``Worker._defaults`` attribute.
  1025. Use ``{k: getattr(worker, k) for k in worker._fields}``.
  1026. - ``Worker.update_heartbeat``
  1027. Use ``Worker.event(None, timestamp, received)``
  1028. - ``Worker.on_online``
  1029. Use ``Worker.event('online', timestamp, received, fields)``
  1030. - ``Worker.on_offline``
  1031. Use ``Worker.event('offline', timestamp, received, fields)``
  1032. - ``Worker.on_heartbeat``
  1033. Use ``Worker.event('heartbeat', timestamp, received, fields)``
  1034. - Removals for class :class:`celery.events.state.Task`:
  1035. - ``Task._defaults`` attribute.
  1036. Use ``{k: getattr(task, k) for k in task._fields}``.
  1037. - ``Task.on_sent``
  1038. Use ``Worker.event('sent', timestamp, received, fields)``
  1039. - ``Task.on_received``
  1040. Use ``Task.event('received', timestamp, received, fields)``
  1041. - ``Task.on_started``
  1042. Use ``Task.event('started', timestamp, received, fields)``
  1043. - ``Task.on_failed``
  1044. Use ``Task.event('failed', timestamp, received, fields)``
  1045. - ``Task.on_retried``
  1046. Use ``Task.event('retried', timestamp, received, fields)``
  1047. - ``Task.on_succeeded``
  1048. Use ``Task.event('succeeded', timestamp, received, fields)``
  1049. - ``Task.on_revoked``
  1050. Use ``Task.event('revoked', timestamp, received, fields)``
  1051. - ``Task.on_unknown_event``
  1052. Use ``Task.event(short_type, timestamp, received, fields)``
  1053. - ``Task.update``
  1054. Use ``Task.event(short_type, timestamp, received, fields)``
  1055. - ``Task.merge``
  1056. Contact us if you need this.
  1057. Magic keyword arguments
  1058. ~~~~~~~~~~~~~~~~~~~~~~~
  1059. Support for the very old magic keyword arguments accepted by tasks is
  1060. finally removed in this version.
  1061. If you are still using these you have to rewrite any task still
  1062. using the old ``celery.decorators`` module and depending
  1063. on keyword arguments being passed to the task,
  1064. for example::
  1065. from celery.decorators import task
  1066. @task()
  1067. def add(x, y, task_id=None):
  1068. print('My task id is %r' % (task_id,))
  1069. should be rewritten into::
  1070. from celery import task
  1071. @task(bind=True)
  1072. def add(self, x, y):
  1073. print('My task id is {0.request.id}'.format(self))
  1074. Removed Settings
  1075. ----------------
  1076. The following settings have been removed, and is no longer supported:
  1077. Logging Settings
  1078. ~~~~~~~~~~~~~~~~
  1079. ===================================== =====================================
  1080. **Setting name** **Replace with**
  1081. ===================================== =====================================
  1082. ``CELERYD_LOG_LEVEL`` :option:`celery worker --loglevel`
  1083. ``CELERYD_LOG_FILE`` :option:`celery worker --logfile`
  1084. ``CELERYBEAT_LOG_LEVEL`` :option:`celery beat --loglevel`
  1085. ``CELERYBEAT_LOG_FILE`` :option:`celery beat --loglevel`
  1086. ``CELERYMON_LOG_LEVEL`` celerymon is deprecated, use flower.
  1087. ``CELERYMON_LOG_FILE`` celerymon is deprecated, use flower.
  1088. ``CELERYMON_LOG_FORMAT`` celerymon is deprecated, use flower.
  1089. ===================================== =====================================
  1090. Task Settings
  1091. ~~~~~~~~~~~~~~
  1092. ===================================== =====================================
  1093. **Setting name** **Replace with**
  1094. ===================================== =====================================
  1095. ``CELERY_CHORD_PROPAGATES`` N/A
  1096. ===================================== =====================================
  1097. Changes to internal API
  1098. -----------------------
  1099. - Module ``celery.datastructures`` renamed to :mod:`celery.utils.collections`.
  1100. - ``celery.utils.datastructures.DependencyGraph`` moved to
  1101. :mod:`celery.utils.graph`.
  1102. - ``celery.utils.jsonify`` is now :func:`celery.utils.serialization.jsonify`.
  1103. - ``celery.utils.strtobool`` is now
  1104. :func:`celery.utils.serialization.strtobool`.
  1105. - ``celery.utils.is_iterable`` has been removed.
  1106. Instead use::
  1107. isinstance(x, collections.Iterable)
  1108. - ``celery.utils.lpmerge`` is now :func:`celery.utils.collections.lpmerge`.
  1109. - ``celery.utils.cry`` is now :func:`celery.utils.debug.cry`.
  1110. - ``celery.utils.isatty`` is now :func:`celery.platforms.isatty`.
  1111. - ``celery.utils.gen_task_name`` is now
  1112. :func:`celery.utils.imports.gen_task_name`.
  1113. - ``celery.utils.deprecated`` is now :func:`celery.utils.deprecated.Callable`
  1114. - ``celery.utils.deprecated_property`` is now
  1115. :func:`celery.utils.deprecated.Property`.
  1116. - ``celery.utils.warn_deprecated`` is now :func:`celery.utils.deprecated.warn`
  1117. .. _v400-deprecations:
  1118. Deprecation Time-line Changes
  1119. =============================
  1120. See the :ref:`deprecation-timeline`.