whatsnew-4.0.rst 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318
  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: 3
  30. Preface
  31. =======
  32. XXX To be written
  33. Wall of Contributors
  34. --------------------
  35. Aaron McMillin, Adam Chainz, Adam Renberg, Adriano Martins de Jesus,
  36. Adrien Guinet, Ahmet Demir, Aitor Gómez-Goiri, Alan Justino,
  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, Amir Rustamzadeh,
  40. Andrea Rabbaglietti, Andrea Rosa, Andrei Fokau, Andrew Rodionoff,
  41. Andrew Stewart, Andriy Yurchuk, Aneil Mallavarapu, Areski Belaid,
  42. Armenak Baburyan, Arthur Vuillard, Artyom Koval, Asif Saifuddin Auvi,
  43. Ask Solem, Balthazar Rouberol, Batiste Bieler, Berker Peksag,
  44. Bert Vanderbauwhede, Brendan Smithyman, Brian Bouterse, Bryce Groff,
  45. Cameron Will, ChangBo Guo, Chris Clark, Chris Duryee, Chris Erway,
  46. Chris Harris, Chris Martin, Chillar Anand, Colin McIntosh, Conrad Kramer,
  47. Corey Farwell, Craig Jellick, Cullen Rhodes, Dallas Marlow, Daniel Devine,
  48. Daniel Wallace, Danilo Bargen, Davanum Srinivas, Dave Smith, David Baumgold,
  49. David Harrigan, David Pravec, Dennis Brakhane, Derek Anderson,
  50. Dmitry Dygalo, Dmitry Malinovsky, Dongweiming, Dudás Ádám,
  51. Dustin J. Mitchell, Ed Morley, Edward Betts, Éloi Rivard, Emmanuel Cazenave,
  52. Fahad Siddiqui, Fatih Sucu, Feanil Patel, Federico Ficarelli, Felix Schwarz,
  53. Felix Yan, Fernando Rocha, Flavio Grossi, Frantisek Holop, Gao Jiangmiao,
  54. George Whewell, Gerald Manipon, Gilles Dartiguelongue, Gino Ledesma, Greg Wilbur,
  55. Guillaume Seguin, Hank John, Hogni Gylfason, Ilya Georgievsky,
  56. Ionel Cristian Mărieș, Ivan Larin, James Pulec, Jared Lewis, Jason Veatch,
  57. Jasper Bryant-Greene, Jeff Widman, Jeremy Tillman, Jeremy Zafran,
  58. Jocelyn Delalande, Joe Jevnik, Joe Sanford, John Anderson, John Barham,
  59. John Kirkham, John Whitlock, Jonathan Vanasco, Joshua Harlow, João Ricardo,
  60. Juan Carlos Ferrer, Juan Rossi, Justin Patrin, Kai Groner, Kevin Harvey,
  61. Kevin Richardson, Komu Wairagu, Konstantinos Koukopoulos, Kouhei Maeda,
  62. Kracekumar Ramaraju, Krzysztof Bujniewicz, Latitia M. Haskins, Len Buckens,
  63. Lev Berman, lidongming, Lorenzo Mancini, Lucas Wiman, Luke Pomfrey,
  64. Luyun Xie, Maciej Obuchowski, Manuel Kaufmann, Marat Sharafutdinov,
  65. Marc Sibson, Marcio Ribeiro, Marin Atanasov Nikolov, Mathieu Fenniak,
  66. Mark Parncutt, Maxime Beauchemin, Maxime Vdb, Mher Movsisyan, Michael Aquilina,
  67. Michael Duane Mooring, Michael Permana, Mickaël Penhard, Mike Attwood,
  68. Mitchel Humpherys, Mohamed Abouelsaoud, Morris Tweed, Morton Fox,
  69. Môshe van der Sterre, Nat Williams, Nathan Van Gheem, Nicolas Unravel,
  70. Nik Nyby, Omer Katz, Omer Korner, Ori Hoch, Paul Pearce, Paulo Bu,
  71. Pavlo Kapyshin, Philip Garnero, Pierre Fersing, Piotr Kilczuk,
  72. Piotr Maślanka, Quentin Pradet, Radek Czajka, Raghuram Srinivasan,
  73. Randy Barlow, Raphael Michel, Rémy Léone, Robert Coup, Robert Kolba,
  74. Rockallite Wulf, Rodolfo Carvalho, Roger Hu, Romuald Brunet, Rongze Zhu,
  75. Ross Deane, Ryan Luckie, Rémy Greinhofer, Samuel Giffard, Samuel Jaillet,
  76. Sergey Azovskov, Sergey Tikhonov, Seungha Kim, Simon Peeters,
  77. Spencer E. Olson, Srinivas Garlapati, Stephen Milner, Steve Peak, Stuart Axon,
  78. Sukrit Khera, Tadej Janež, Taha Jahangir, Takeshi Kanemoto, Tayfun Sen,
  79. Tewfik Sadaoui, Thomas French, Thomas Grainger, Tomas Machalek,
  80. Tobias Schottdorf, Tocho Tochev, Valentyn Klindukh, Vic Kumar,
  81. Vladimir Bolshakov, Vladimir Gorbunov, Wayne Chang, Wieland Hoffmann,
  82. Wido den Hollander, Wil Langford, Will Thompson, William King, Yury Selivanov,
  83. Vytis Banaitis, Zoran Pavlovic, Xin Li, 許邱翔, :github_user:`allenling`,
  84. :github_user:`alzeih`, :github_user:`bastb`, :github_user:`bee-keeper`,
  85. :github_user:`ffeast`, :github_user:`firefly4268`,
  86. :github_user:`flyingfoxlee`, :github_user:`gdw2`, :github_user:`gitaarik`,
  87. :github_user:`hankjin`, :github_user:`lvh`, :github_user:`m-vdb`,
  88. :github_user:`kindule`, :github_user:`mdk`:, :github_user:`michael-k`,
  89. :github_user:`mozillazg`, :github_user:`nokrik`, :github_user:`ocean1`,
  90. :github_user:`orlo666`, :github_user:`raducc`, :github_user:`wanglei`,
  91. :github_user:`worldexception`, :github_user:`xBeAsTx`.
  92. Upgrading from Celery 3.1
  93. =========================
  94. Step 1: Upgrade to Celery 3.1.25
  95. --------------------------------
  96. If you haven't already, the first step is to upgrade to Celery 3.1.25.
  97. This version adds foreward compatibility to the new message protocol,
  98. so that you can incrementally upgrade from 3.1 to 4.0.
  99. Deploy the workers first by upgrading to 3.1.25, this means these
  100. workers can process messages sent by clients using both 3.1 and 4.0.
  101. After the workers are upgraded you can upgrade the clients (e.g. web servers).
  102. Step 2: Update your configuration with the new setting names
  103. ------------------------------------------------------------
  104. This version radically changes the configuration setting names,
  105. to be more consistent.
  106. The changes are fully backwards compatible, so you have the option to wait
  107. until the old setting names are deprecated, but to ease the transition
  108. we have included a command-line utility that rewrites your settings
  109. automatically.
  110. See :ref:`v400-upgrade-settings` for more information.
  111. Step 3: Read the important notes in this document
  112. -------------------------------------------------
  113. Make sure you are not affected by any of the important upgrade notes
  114. mentioned in the following section.
  115. An especially important note is that Celery now checks the arguments
  116. you send to a task by matching it to the signature (:ref:`v400-typing`).
  117. Step 4: Upgrade to Celery 4.0
  118. -----------------------------
  119. At this point you can upgrade your workers and clients with the new version.
  120. .. _v400-important:
  121. Important Notes
  122. ===============
  123. Dropped support for Python 2.6
  124. ------------------------------
  125. Celery now requires Python 2.7 or later,
  126. and also drops support for Python 3.3 so supported versions are:
  127. - CPython 2.7
  128. - CPython 3.4
  129. - CPython 3.5
  130. - PyPy 5.4 (``pypy2``)
  131. - PyPy 5.5-alpha (``pypy3``)
  132. Last major version to support Python 2
  133. --------------------------------------
  134. Starting from Celery 5.0 only Python 3.5+ will be supported.
  135. To make sure you're not affected by this change you should pin
  136. the Celery version in your requirements file, either to a specific
  137. version: ``celery==4.0.0``, or a range: ``celery>=4.0,<5.0``.
  138. Dropping support for Python 2 will enable us to remove massive
  139. amounts of compatibility code, and going with Python 3.5 allows
  140. us to take advantage of typing, async/await, asyncio, and similar
  141. concepts there's no alternative for in older versions.
  142. Celery 4.x will continue to work on Python 2.7, 3.4, 3.5; just as Celery 3.x
  143. still works on Python 2.6.
  144. Django support
  145. --------------
  146. Celery 4.x requires Django 1.8 or later, but we really recommend
  147. using at least Django 1.9 for the new ``transaction.on_commit`` feature.
  148. A common problem when calling tasks from Django is when the task is related
  149. to a model change, and you wish to cancel the task if the transaction is
  150. rolled back, or ensure the task is only executed after the changes have been
  151. written to the database.
  152. ``transaction.on_commit`` enables you to solve this problem by adding
  153. the task as a callback to be called only when the transaction is committed.
  154. Example usage:
  155. .. code-block:: python
  156. from functools import partial
  157. from django.db import transaction
  158. from .models import Article, Log
  159. from .tasks import send_article_created_notification
  160. def create_article(request):
  161. with transaction.atomic():
  162. article = Article.objects.create(**request.POST)
  163. # send this task only if the rest of the transaction succeeds.
  164. transaction.on_commit(partial(
  165. send_article_created_notification.delay, article_id=article.pk)
  166. Log.objects.create(type=Log.ARTICLE_CREATED, object_pk=article.pk)
  167. Removed features
  168. ----------------
  169. - Microsoft Windows is no longer supported.
  170. The test suite is passing, and Celery seems to be working with Windows,
  171. but we make no guarantees as we are unable to diagnose issues on this
  172. platform.
  173. - Jython is no longer supported.
  174. Features removed for simplicity
  175. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  176. - Webhook task machinery (``celery.task.http``) has been removed.
  177. Nowadays it's easy to use the :pypi:`requests` module to write
  178. webhook tasks manually. We would love to use requests but we
  179. are simply unable to as there's a very vocal 'anti-dependency'
  180. mob in the Python community
  181. If you need backwards compatibility
  182. you can simply copy + paste the 3.1 version of the module and make sure
  183. it's imported by the worker:
  184. https://github.com/celery/celery/blob/3.1/celery/task/http.py
  185. - Task no longer sends error emails.
  186. This also removes support for ``app.mail_admins``, and any functionality
  187. related to sending emails.
  188. - ``celery.contrib.batches`` has been removed.
  189. This was an experimental feature, so not covered by our deprecation
  190. timeline guarantee.
  191. You can copy and pase the existing batches code for use within your projects:
  192. https://github.com/celery/celery/blob/3.1/celery/contrib/batches.py
  193. Features removed for lack of funding
  194. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195. We announced with the 3.1 release that some transports were
  196. moved to experimental status, and that there'd be no official
  197. support for the transports, citing a lack of resources.
  198. As this subtle hint for the need of funding failed
  199. we've removed them completely, breaking backwards compatibility.
  200. - Using the Django ORM as a broker is no longer supported.
  201. You can still use the Django ORM as a result backend:
  202. see :ref:`django-celery-results` section for more information.
  203. - Using SQLAlchemy as a broker is no longer supported.
  204. You can still use SQLAlchemy as a result backend.
  205. - Using CouchDB as a broker is no longer supported.
  206. You can still use CouchDB as a result backend.
  207. - Using IronMQ as a broker is no longer supported.
  208. - Using Beanstalk as a broker is no longer supported.
  209. In addition some features have been removed completely so that
  210. attempting to use them will raise an exception:
  211. - The ``--autoreload`` feature has been removed.
  212. This was an experimental feature, and not covered by our deprecation
  213. timeline guarantee. The flag is removed completely so the worker
  214. will crash at startup when present. Luckily this
  215. flag isn't used in production systems.
  216. - The experimental ``threads`` pool is no longer supported and has been removed.
  217. - The force_execv feature is no longer supported.
  218. The ``celery worker`` command now ignores the ``--no-execv``,
  219. ``--force-execv``, and the ``CELERYD_FORCE_EXECV`` setting.
  220. This flag will be removed completely in 5.0 and the worker
  221. will raise an error.
  222. - The old legacy "amqp" result backend has been deprecated, and will
  223. be removed in Celery 5.0.
  224. Please use the ``rpc`` result backend for RPC-style calls, and a
  225. persistent result backend for multi-consumer results.
  226. **Now to the good news**...
  227. New Task Message Protocol
  228. -------------------------
  229. .. :sha:`e71652d384b1b5df2a4e6145df9f0efb456bc71c`
  230. This version introduces a brand new task message protocol,
  231. the first major change to the protocol since the beginning of the project.
  232. The new protocol is enabled by default in this version and since the new
  233. version isn't backwards compatible you have to be careful when upgrading.
  234. The 3.1.25 version was released to add compatibility with the new protocol
  235. so the easiest way to upgrade is to upgrade to that version first, then
  236. upgrade to 4.0 in a second deployment.
  237. If you wish to keep using the old protocol you may also configure
  238. the protocol version number used:
  239. .. code-block:: python
  240. app = Celery()
  241. app.conf.task_protocol = 1
  242. Read more about the features available in the new protocol in the news
  243. section found later in this document.
  244. .. _v400-upgrade-settings:
  245. Lowercase setting names
  246. -----------------------
  247. In the pursuit of beauty all settings are now renamed to be in all
  248. lowercase and some setting names have been renamed for consistency.
  249. This change is fully backwards compatible so you can still use the uppercase
  250. setting names, but we would like you to upgrade as soon as possible and
  251. you can this automatically using the :program:`celery upgrade settings`
  252. command:
  253. .. code-block:: console
  254. $ celery upgrade settings proj/settings.py
  255. This command will modify your module in-place to use the new lower-case
  256. names (if you want uppercase with a "``CELERY``" prefix see block below),
  257. and save a backup in :file:`proj/settings.py.orig`.
  258. .. admonition:: For Django users and others who want to keep uppercase names
  259. If you're loading Celery configuration from the Django settings module
  260. then you'll want to keep using the uppercase names.
  261. You also want to use a ``CELERY_`` prefix so that no Celery settings
  262. collide with Django settings used by other apps.
  263. To do this, you'll first need to convert your settings file
  264. to use the new consistent naming scheme, and add the prefix to all
  265. Celery related settings:
  266. .. code-block:: console
  267. $ celery upgrade settings --django proj/settings.py
  268. After upgrading the settings file, you need to set the prefix explicitly
  269. in your ``proj/celery.py`` module:
  270. .. code-block:: python
  271. app.config_from_object('django.conf:settings', namespace='CELERY')
  272. You can find the most up to date Django Celery integration example
  273. here: :ref:`django-first-steps`.
  274. .. note::
  275. This will also add a prefix to settings that didn't previously
  276. have one, for example ``BROKER_URL`` should be written
  277. ``CELERY_BROKER_URL`` with a namespace of ``CELERY``
  278. ``CELERY_BROKER_URL``.
  279. Luckily you don't have to manually change the files, as
  280. the :program:`celery upgrade settings --django` program should do the
  281. right thing.
  282. The loader will try to detect if your configuration is using the new format,
  283. and act accordingly, but this also means you're not allowed to mix and
  284. match new and old setting names, that's unless you provide a value for both
  285. alternatives.
  286. The major difference between previous versions, apart from the lower case
  287. names, are the renaming of some prefixes, like ``celerybeat_`` to ``beat_``,
  288. ``celeryd_`` to ``worker_``.
  289. The ``celery_`` prefix has also been removed, and task related settings
  290. from this name-space is now prefixed by ``task_``, worker related settings
  291. with ``worker_``.
  292. Apart from this most of the settings will be the same in lowercase, apart from
  293. a few special ones:
  294. ===================================== ==========================================================
  295. **Setting name** **Replace with**
  296. ===================================== ==========================================================
  297. ``CELERY_MAX_CACHED_RESULTS`` :setting:`result_cache_max`
  298. ``CELERY_MESSAGE_COMPRESSION`` :setting:`result_compression`/:setting:`task_compression`.
  299. ``CELERY_TASK_RESULT_EXPIRES`` :setting:`result_expires`
  300. ``CELERY_RESULT_DBURI`` :setting:`result_backend`
  301. ``CELERY_RESULT_ENGINE_OPTIONS`` :setting:`database_engine_options`
  302. ``-*-_DB_SHORT_LIVED_SESSIONS`` :setting:`database_short_lived_sessions`
  303. ``CELERY_RESULT_DB_TABLE_NAMES`` :setting:`database_db_names`
  304. ``CELERY_ACKS_LATE`` :setting:`task_acks_late`
  305. ``CELERY_ALWAYS_EAGER`` :setting:`task_always_eager`
  306. ``CELERY_ANNOTATIONS`` :setting:`task_annotations`
  307. ``CELERY_MESSAGE_COMPRESSION`` :setting:`task_compression`
  308. ``CELERY_CREATE_MISSING_QUEUES`` :setting:`task_create_missing_queues`
  309. ``CELERY_DEFAULT_DELIVERY_MODE`` :setting:`task_default_delivery_mode`
  310. ``CELERY_DEFAULT_EXCHANGE`` :setting:`task_default_exchange`
  311. ``CELERY_DEFAULT_EXCHANGE_TYPE`` :setting:`task_default_exchange_type`
  312. ``CELERY_DEFAULT_QUEUE`` :setting:`task_default_queue`
  313. ``CELERY_DEFAULT_RATE_LIMIT`` :setting:`task_default_rate_limit`
  314. ``CELERY_DEFAULT_ROUTING_KEY`` :setting:`task_default_routing_key`
  315. ``-"-_EAGER_PROPAGATES_EXCEPTIONS`` :setting:`task_eager_propagates`
  316. ``CELERY_IGNORE_RESULT`` :setting:`task_ignore_result`
  317. ``CELERY_TASK_PUBLISH_RETRY`` :setting:`task_publish_retry`
  318. ``CELERY_TASK_PUBLISH_RETRY_POLICY`` :setting:`task_publish_retry_policy`
  319. ``CELERY_QUEUES`` :setting:`task_queues`
  320. ``CELERY_ROUTES`` :setting:`task_routes`
  321. ``CELERY_SEND_TASK_SENT_EVENT`` :setting:`task_send_sent_event`
  322. ``CELERY_TASK_SERIALIZER`` :setting:`task_serializer`
  323. ``CELERYD_TASK_SOFT_TIME_LIMIT`` :setting:`task_soft_time_limit`
  324. ``CELERYD_TASK_TIME_LIMIT`` :setting:`task_time_limit`
  325. ``CELERY_TRACK_STARTED`` :setting:`task_track_started`
  326. ``CELERY_DISABLE_RATE_LIMITS`` :setting:`worker_disable_rate_limits`
  327. ``CELERY_ENABLE_REMOTE_CONTROL`` :setting:`worker_enable_remote_control`
  328. ``CELERYD_SEND_EVENTS`` :setting:`worker_send_task_events`
  329. ===================================== ==========================================================
  330. You can see a full table of the changes in :ref:`conf-old-settings-map`.
  331. Json is now the default serializer
  332. ----------------------------------
  333. The time has finally come to end the reign of :mod:`pickle` as the default
  334. serialization mechanism, and json is the default serializer starting from this
  335. version.
  336. This change was :ref:`announced with the release of Celery 3.1
  337. <last-version-to-enable-pickle>`.
  338. If you're still depending on :mod:`pickle` being the default serializer,
  339. then you have to configure your app before upgrading to 4.0:
  340. .. code-block:: python
  341. task_serializer = 'pickle'
  342. result_serializer = 'pickle'
  343. accept_content = {'pickle'}
  344. The Json serializer now also supports some additional types:
  345. - :class:`~datetime.datetime`, :class:`~datetime.time`, :class:`~datetime.date`
  346. Converted to json text, in ISO-8601 format.
  347. - :class:`~decimal.Decimal`
  348. Converted to json text.
  349. - :class:`django.utils.functional.Promise`
  350. Django only: Lazy strings used for translation etc., are evaluated
  351. and conversion to a json type is attempted.
  352. - :class:`uuid.UUID`
  353. Converted to json text.
  354. You can also define a ``__json__`` method on your custom classes to support
  355. JSON serialization (must return a json compatible type):
  356. .. code-block:: python
  357. class Person:
  358. first_name = None
  359. last_name = None
  360. address = None
  361. def __json__(self):
  362. return {
  363. 'first_name': self.first_name,
  364. 'last_name': self.last_name,
  365. 'address': self.address,
  366. }
  367. The Task base class no longer automatically register tasks
  368. ----------------------------------------------------------
  369. The :class:`~@Task` class is no longer using a special meta-class
  370. that automatically registers the task in the task registry.
  371. Instead this is now handled by the :class:`@task` decorators.
  372. If you're still using class based tasks, then you need to register
  373. these manually:
  374. .. code-block:: python
  375. class CustomTask(Task):
  376. def run(self):
  377. print('running')
  378. app.tasks.register(CustomTask())
  379. The best practice is to use custom task classes only for overriding
  380. general behavior, and then using the task decorator to realize the task:
  381. .. code-block:: python
  382. @app.task(bind=True, base=CustomTask)
  383. def custom(self):
  384. print('running')
  385. This change also means that the ``abstract`` attribute of the task
  386. no longer has any effect.
  387. .. _v400-typing:
  388. Task argument checking
  389. ----------------------
  390. The arguments of the task are now verified when calling the task,
  391. even asynchronously:
  392. .. code-block:: pycon
  393. >>> @app.task
  394. ... def add(x, y):
  395. ... return x + y
  396. >>> add.delay(8, 8)
  397. <AsyncResult: f59d71ca-1549-43e0-be41-4e8821a83c0c>
  398. >>> add.delay(8)
  399. Traceback (most recent call last):
  400. File "<stdin>", line 1, in <module>
  401. File "celery/app/task.py", line 376, in delay
  402. return self.apply_async(args, kwargs)
  403. File "celery/app/task.py", line 485, in apply_async
  404. check_arguments(*(args or ()), **(kwargs or {}))
  405. TypeError: add() takes exactly 2 arguments (1 given)
  406. You can disable the argument checking for any task by setting its
  407. :attr:`~@Task.typing` attribute to :const:`False`:
  408. .. code-block:: pycon
  409. >>> @app.task(typing=False)
  410. ... def add(x, y):
  411. ... return x + y
  412. Or if you would like to disable this completely for all tasks
  413. you can pass ``strict_typing=False`` when creating the app:
  414. .. code-block::
  415. app = Celery(..., strict_typing=False)
  416. Redis Events not backward compatible
  417. ------------------------------------
  418. The Redis ``fanout_patterns`` and ``fanout_prefix`` transport
  419. options are now enabled by default.
  420. Workers/monitors without these flags enabled won't be able to
  421. see workers with this flag disabled. They can still execute tasks,
  422. but they cannot receive each others monitoring messages.
  423. You can upgrade in a backward compatible manner by first configuring
  424. your 3.1 workers and monitors to enable the settings, before the final
  425. upgrade to 4.0:
  426. .. code-block:: python
  427. BROKER_TRANSPORT_OPTIONS = {
  428. 'fanout_patterns': True,
  429. 'fanout_prefix': True,
  430. }
  431. Redis Priorities Reversed
  432. -------------------------
  433. Priority 0 is now lowest, 9 is highest.
  434. This change was made to make priority support consistent with how
  435. it works in AMQP.
  436. Contributed by **Alex Koshelev**.
  437. Django: Auto-discover now supports Django app configurations
  438. ------------------------------------------------------------
  439. The ``autodiscover_tasks()`` function can now be called without arguments,
  440. and the Django handler will automatically find your installed apps:
  441. .. code-block:: python
  442. app.autodiscover_tasks()
  443. The Django integration :ref:`example in the documentation
  444. <django-first-steps>` has been updated to use the argument-less call.
  445. This also ensures compatibility with the new, ehm, ``AppConfig`` stuff
  446. introduced in recent Django versions.
  447. Worker direct queues no longer use auto-delete
  448. ----------------------------------------------
  449. Workers/clients running 4.0 will no longer be able to send
  450. worker direct messages to workers running older versions, and vice versa.
  451. If you're relying on worker direct messages you should upgrade
  452. your 3.x workers and clients to use the new routing settings first,
  453. by replacing :func:`celery.utils.worker_direct` with this implementation:
  454. .. code-block:: python
  455. from kombu import Exchange, Queue
  456. worker_direct_exchange = Exchange('C.dq2')
  457. def worker_direct(hostname):
  458. return Queue(
  459. '{hostname}.dq2'.format(hostname),
  460. exchange=worker_direct_exchange,
  461. routing_key=hostname,
  462. )
  463. This feature closed Issue #2492.
  464. Old command-line programs removed
  465. ---------------------------------
  466. Installing Celery will no longer install the ``celeryd``,
  467. ``celerybeat`` and ``celeryd-multi`` programs.
  468. This was announced with the release of Celery 3.1, but you may still
  469. have scripts pointing to the old names, so make sure you update these
  470. to use the new umbrella command:
  471. +-------------------+--------------+-------------------------------------+
  472. | Program | New Status | Replacement |
  473. +===================+==============+=====================================+
  474. | ``celeryd`` | **REMOVED** | :program:`celery worker` |
  475. +-------------------+--------------+-------------------------------------+
  476. | ``celerybeat`` | **REMOVED** | :program:`celery beat` |
  477. +-------------------+--------------+-------------------------------------+
  478. | ``celeryd-multi`` | **REMOVED** | :program:`celery multi` |
  479. +-------------------+--------------+-------------------------------------+
  480. .. _v400-news:
  481. News
  482. ====
  483. New protocol highlights
  484. -----------------------
  485. The new protocol fixes many problems with the old one, and enables
  486. some long-requested features:
  487. - Most of the data are now sent as message headers, instead of being
  488. serialized with the message body.
  489. In version 1 of the protocol the worker always had to deserialize
  490. the message to be able to read task meta-data like the task id,
  491. name, etc. This also meant that the worker was forced to double-decode
  492. the data, first deserializing the message on receipt, serializing
  493. the message again to send to child process, then finally the child process
  494. deserializes the message again.
  495. Keeping the meta-data fields in the message headers means the worker
  496. doesn't actually have to decode the payload before delivering
  497. the task to the child process, and also that it's now possible
  498. for the worker to reroute a task written in a language different
  499. from Python to a different worker.
  500. - A new ``lang`` message header can be used to specify the programming
  501. language the task is written in.
  502. - Worker stores results for internal errors like ``ContentDisallowed``,
  503. and other deserialization errors.
  504. - Worker stores results and sends monitoring events for unregistered
  505. task errors.
  506. - Worker calls callbacks/errbacks even when the result is sent by the
  507. parent process (e.g., :exc:`WorkerLostError` when a child process
  508. terminates, deserialization errors, unregistered tasks).
  509. - A new ``origin`` header contains information about the process sending
  510. the task (worker node-name, or PID and host-name information).
  511. - A new ``shadow`` header allows you to modify the task name used in logs.
  512. This is useful for dispatch like patterns, like a task that calls
  513. any function using pickle (don't do this at home):
  514. .. code-block:: python
  515. from celery import Task
  516. from celery.utils.imports import qualname
  517. class call_as_task(Task):
  518. def shadow_name(self, args, kwargs, options):
  519. return 'call_as_task:{0}'.format(qualname(args[0]))
  520. def run(self, fun, *args, **kwargs):
  521. return fun(*args, **kwargs)
  522. call_as_task = app.tasks.register(call_as_task())
  523. - New ``argsrepr`` and ``kwargsrepr`` fields contain textual representations
  524. of the task arguments (possibly truncated) for use in logs, monitors, etc.
  525. This means the worker doesn't have to deserialize the message payload
  526. to display the task arguments for informational purposes.
  527. - Chains now use a dedicated ``chain`` field enabling support for chains
  528. of thousands and more tasks.
  529. - New ``parent_id`` and ``root_id`` headers adds information about
  530. a tasks relationship with other tasks.
  531. - ``parent_id`` is the task id of the task that called this task
  532. - ``root_id`` is the first task in the work-flow.
  533. These fields can be used to improve monitors like flower to group
  534. related messages together (like chains, groups, chords, complete
  535. work-flows, etc).
  536. - ``app.TaskProducer`` replaced by :meth:`@amqp.create_task_message` and
  537. :meth:`@amqp.send_task_message`.
  538. Dividing the responsibilities into creating and sending means that
  539. people who want to send messages using a Python AMQP client directly,
  540. doesn't have to implement the protocol.
  541. The :meth:`@amqp.create_task_message` method calls either
  542. :meth:`@amqp.as_task_v2`, or :meth:`@amqp.as_task_v1` depending
  543. on the configured task protocol, and returns a special
  544. :class:`~celery.app.amqp.task_message` tuple containing the
  545. headers, properties and body of the task message.
  546. .. seealso::
  547. The new task protocol is documented in full here:
  548. :ref:`message-protocol-task-v2`.
  549. Prefork Pool Improvements
  550. -------------------------
  551. Tasks now log from the child process
  552. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  553. Logging of task success/failure now happens from the child process
  554. executing the task. As a result logging utilities,
  555. like Sentry can get full information about tasks, including
  556. variables in the traceback stack.
  557. ``-Ofair`` is now the default scheduling strategy
  558. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  559. To re-enable the default behavior in 3.1 use the ``-Ofast`` command-line
  560. option.
  561. There's been lots of confusion about what the ``-Ofair`` command-line option
  562. does, and using the term "prefetch" in explanations have probably not helped
  563. given how confusing this terminology is in AMQP.
  564. When a Celery worker using the prefork pool receives a task, it needs to
  565. delegate that task to a child process for execution.
  566. The prefork pool has a configurable number of child processes
  567. (``--concurrency``) that can be used to execute tasks, and each child process
  568. uses pipes/sockets to communicate with the parent process:
  569. - inqueue (pipe/socket): parent sends task to the child process
  570. - outqueue (pipe/socket): child sends result/return value to the parent.
  571. In Celery 3.1 the default scheduling mechanism was simply to send
  572. the task to the first ``inqueue`` that was writable, with some heuristics
  573. to make sure we round-robin between them to ensure each child process
  574. would receive the same amount of tasks.
  575. This means that in the default scheduling strategy, a worker may send
  576. tasks to the same child process that is already executing a task. If that
  577. task is long running, it may block the waiting task for a long time. Even
  578. worse, hundreds of short-running tasks may be stuck behind a long running task
  579. even when there are child processes free to do work.
  580. The ``-Ofair`` scheduling strategy was added to avoid this situation,
  581. and when enabled it adds the rule that no task should be sent to the a child
  582. process that is already executing a task.
  583. The fair scheduling strategy may perform slightly worse if you have only
  584. short running tasks.
  585. Limit child process resident memory size
  586. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  587. .. :sha:`5cae0e754128750a893524dcba4ae030c414de33`
  588. You can now limit the maximum amount of memory allocated per prefork
  589. pool child process by setting the worker
  590. :option:`--max-memory-per-child <celery worker --max-memory-per-child>` option,
  591. or the :setting:`worker_max_memory_per_child` setting.
  592. The limit is for RSS/resident memory size and is specified in kilobytes.
  593. A child process having exceeded the limit will be terminated and replaced
  594. with a new process after the currently executing task returns.
  595. See :ref:`worker-max-memory-per-child` for more information.
  596. Contributed by **Dave Smith**.
  597. One log-file per child process
  598. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  599. Init-scrips and :program:`celery multi` now uses the `%I` log file format
  600. option (e.g., :file:`/var/log/celery/%n%I.log`).
  601. This change was necessary to ensure each child
  602. process has a separate log file after moving task logging
  603. to the child process, as multiple processes writing to the same
  604. log file can cause corruption.
  605. You're encouraged to upgrade your init-scripts and
  606. :program:`celery multi` arguments to use this new option.
  607. Transports
  608. ----------
  609. RabbitMQ priority queue support
  610. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  611. See :ref:`routing-options-rabbitmq-priorities` for more information.
  612. Contributed by **Gerald Manipon**.
  613. Configure broker URL for read/write separately
  614. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  615. New :setting:`broker_read_url` and :setting:`broker_write_url` settings
  616. have been added so that separate broker URLs can be provided
  617. for connections used for consuming/publishing.
  618. In addition to the configuration options, two new methods have been
  619. added the app API:
  620. - ``app.connection_for_read()``
  621. - ``app.connection_for_write()``
  622. These should now be used in place of ``app.connection()`` to specify
  623. the intent of the required connection.
  624. .. note::
  625. Two connection pools are available: ``app.pool`` (read), and
  626. ``app.producer_pool`` (write). The latter doesn't actually give connections
  627. but full :class:`kombu.Producer` instances.
  628. .. code-block:: python
  629. def publish_some_message(app, producer=None):
  630. with app.producer_or_acquire(producer) as producer:
  631. ...
  632. def consume_messages(app, connection=None):
  633. with app.connection_or_acquire(connection) as connection:
  634. ...
  635. RabbitMQ queue extensions support
  636. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  637. Queue declarations can now set a message TTL and queue expiry time directly,
  638. by using the ``message_ttl`` and ``expires`` arguments
  639. New arguments have been added to :class:`~kombu.Queue` that lets
  640. you directly and conveniently configure RabbitMQ queue extensions
  641. in queue declarations:
  642. - ``Queue(expires=20.0)``
  643. Set queue expiry time in float seconds.
  644. See :attr:`kombu.Queue.expires`.
  645. - ``Queue(message_ttl=30.0)``
  646. Set queue message time-to-live float seconds.
  647. See :attr:`kombu.Queue.message_ttl`.
  648. - ``Queue(max_length=1000)``
  649. Set queue max length (number of messages) as int.
  650. See :attr:`kombu.Queue.max_length`.
  651. - ``Queue(max_length_bytes=1000)``
  652. Set queue max length (message size total in bytes) as int.
  653. See :attr:`kombu.Queue.max_length_bytes`.
  654. - ``Queue(max_priority=10)``
  655. Declare queue to be a priority queue that routes messages
  656. based on the ``priority`` field of the message.
  657. See :attr:`kombu.Queue.max_priority`.
  658. Amazon SQS transport now officially supported
  659. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  660. The SQS broker transport has been rewritten to use async I/O and as such
  661. joins RabbitMQ, Redis and QPid as officially supported transports.
  662. The new implementation also takes advantage of long polling,
  663. and closes several issues related to using SQS as a broker.
  664. This work was sponsored by Nextdoor.
  665. Apache QPid transport now officially supported
  666. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  667. Contributed by **Brian Bouterse**.
  668. Redis: Support for Sentinel
  669. ---------------------------
  670. You can point the connection to a list of sentinel URLs like:
  671. .. code-block:: text
  672. sentinel://0.0.0.0:26379;sentinel://0.0.0.0:26380/...
  673. where each sentinel is separated by a `;`. Multiple sentinels are handled
  674. by :class:`kombu.Connection` constructor, and placed in the alternative
  675. list of servers to connect to in case of connection failure.
  676. Contributed by **Sergey Azovskov**, and **Lorenzo Mancini**.
  677. Tasks
  678. -----
  679. Task Auto-retry Decorator
  680. ~~~~~~~~~~~~~~~~~~~~~~~~~
  681. Writing custom retry handling for exception events is so common
  682. that we now have built-in support for it.
  683. For this a new ``autoretry_for`` argument is now supported by
  684. the task decorators, where you can specify a tuple of exceptions
  685. to automatically retry for:
  686. .. code-block:: python
  687. from twitter.exceptions import FailWhaleError
  688. @app.task(autoretry_for=(FailWhaleError,))
  689. def refresh_timeline(user):
  690. return twitter.refresh_timeline(user)
  691. See :ref:`task-autoretry` for more information.
  692. Contributed by **Dmitry Malinovsky**.
  693. .. :sha:`75246714dd11e6c463b9dc67f4311690643bff24`
  694. ``Task.replace`` Improvements
  695. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  696. - ``self.replace(signature)`` can now replace any task, chord or group,
  697. and the signature to replace with can be a chord, group or any other
  698. type of signature.
  699. - No longer inherits the callbacks and errbacks of the existing task.
  700. If you replace a node in a tree, then you wouldn't expect the new node to
  701. inherit the children of the old node.
  702. - ``Task.replace_in_chord`` has been removed, use ``.replace`` instead.
  703. - If the replacement is a group, that group will be automatically converted
  704. to a chord, where the callback "accumulates" the results of the group tasks.
  705. A new built-in task (`celery.accumulate` was added for this purpose)
  706. Contributed by **Steeve Morin**, and **Ask Solem**.
  707. Remote Task Tracebacks
  708. ~~~~~~~~~~~~~~~~~~~~~~
  709. The new :setting:`task_remote_tracebacks` will make task tracebacks more
  710. useful by injecting the stack of the remote worker.
  711. This feature requires the additional :pypi:`tblib` library.
  712. Contributed by **Ionel Cristian Mărieș**.
  713. Handling task connection errors
  714. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  715. Connection related errors occuring while sending a task is now re-raised
  716. as a :exc:`kombu.exceptions.OperationalError` error:
  717. .. code-block:: pycon
  718. >>> try:
  719. ... add.delay(2, 2)
  720. ... except add.OperationalError as exc:
  721. ... print('Could not send task %r: %r' % (add, exc))
  722. See :ref:`calling-connection-errors` for more information.
  723. Gevent/Eventlet: Dedicated thread for consuming results
  724. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  725. When using :pypi:`gevent`, or :pypi:`eventlet` there is now a single
  726. thread responsible for consuming events.
  727. This means that if you have many calls retrieving results, there will be
  728. a dedicated thread for consuming them:
  729. .. code-block:: python
  730. result = add.delay(2, 2)
  731. # this call will delegate to the result consumer thread:
  732. # once the consumer thread has received the result this greenlet can
  733. # continue.
  734. value = result.get(timeout=3)
  735. This makes performing RPC calls when using gevent/eventlet perform much
  736. better.
  737. ``AsyncResult.then(on_success, on_error)``
  738. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  739. The AsyncResult API has been extended to support the :class:`~vine.promise` protocol.
  740. This currently only works with the RPC (amqp) and Redis result backends, but
  741. lets you attach callbacks to when tasks finish:
  742. .. code-block:: python
  743. import gevent.monkey
  744. monkey.patch_all()
  745. import time
  746. from celery import Celery
  747. app = Celery(broker='amqp://', backend='rpc')
  748. @app.task
  749. def add(x, y):
  750. return x + y
  751. def on_result_ready(result):
  752. print('Received result for id %r: %r' % (result.id, result.result,))
  753. add.delay(2, 2).then(on_result_ready)
  754. time.sleep(3) # run gevent event loop for a while.
  755. Demonstrated using gevent here, but really this is an API that's more useful
  756. in callback-based event loops like :pypi:`twisted`, or :pypi:`tornado`.
  757. New Task Router API
  758. ~~~~~~~~~~~~~~~~~~~
  759. The :setting:`task_routes` setting can now hold functions, and map routes
  760. now support glob patterns and regexes.
  761. Instead of using router classes you can now simply define a function:
  762. .. code-block:: python
  763. def route_for_task(name, args, kwargs, options, task=None, **kwargs):
  764. from proj import tasks
  765. if name == tasks.add.name:
  766. return {'queue': 'hipri'}
  767. If you don't need the arguments you can use start arguments, just make
  768. sure you always also accept star arguments so that we have the ability
  769. to add more features in the future:
  770. .. code-block:: python
  771. def route_for_task(name, *args, **kwargs):
  772. from proj import tasks
  773. if name == tasks.add.name:
  774. return {'queue': 'hipri', 'priority': 9}
  775. Both the ``options`` argument and the new ``task`` keyword argument
  776. are new to the function-style routers, and will make it easier to write
  777. routers based on execution options, or properties of the task.
  778. The optional ``task`` keyword argument won't be set if a task is called
  779. by name using :meth:`@send_task`.
  780. For more examples, including using glob/regexes in routers please see
  781. :setting:`task_routes` and :ref:`routing-automatic`.
  782. Canvas Refactor
  783. ~~~~~~~~~~~~~~~
  784. The canvas/work-flow implementation have been heavily refactored
  785. to fix some long outstanding issues.
  786. .. :sha:`d79dcd8e82c5e41f39abd07ffed81ca58052bcd2`
  787. .. :sha:`1e9dd26592eb2b93f1cb16deb771cfc65ab79612`
  788. .. :sha:`e442df61b2ff1fe855881c1e2ff9acc970090f54`
  789. .. :sha:`0673da5c09ac22bdd49ba811c470b73a036ee776`
  790. - Error callbacks can now take real exception and traceback instances
  791. (Issue #2538).
  792. .. code-block:: pycon
  793. >>> add.s(2, 2).on_error(log_error.s()).delay()
  794. Where ``log_error`` could be defined as:
  795. .. code-block:: python
  796. @app.task
  797. def log_error(request, exc, traceback):
  798. with open(os.path.join('/var/errors', request.id), 'a') as fh:
  799. print('--\n\n{0} {1} {2}'.format(
  800. task_id, exc, traceback), file=fh)
  801. See :ref:`guide-canvas` for more examples.
  802. - ``chain(a, b, c)`` now works the same as ``a | b | c``.
  803. This means chain may no longer return an instance of ``chain``,
  804. instead it may optimize the workflow so that e.g. two groups
  805. chained together becomes one group.
  806. - Now unrolls groups within groups into a single group (Issue #1509).
  807. - chunks/map/starmap tasks now routes based on the target task
  808. - chords and chains can now be immutable.
  809. - Fixed bug where serialized signatures weren't converted back into
  810. signatures (Issue #2078)
  811. Fix contributed by **Ross Deane**.
  812. - Fixed problem where chains and groups didn't work when using JSON
  813. serialization (Issue #2076).
  814. Fix contributed by **Ross Deane**.
  815. - Creating a chord no longer results in multiple values for keyword
  816. argument 'task_id' (Issue #2225).
  817. Fix contributed by **Aneil Mallavarapu**.
  818. - Fixed issue where the wrong result is returned when a chain
  819. contains a chord as the penultimate task.
  820. Fix contributed by **Aneil Mallavarapu**.
  821. - Special case of ``group(A.s() | group(B.s() | C.s()))`` now works.
  822. - Chain: Fixed bug with incorrect id set when a subtask is also a chain.
  823. - ``group | group`` is now flattened into a single group (Issue #2573).
  824. - Fixed issue where ``group | task`` wasn't upgrading correctly
  825. to chord (Issue #2922).
  826. - Chords now properly sets ``result.parent`` links.
  827. - ``chunks``/``map``/``starmap`` are now routed based on the target task.
  828. - ``Signature.link`` now works when argument is scalar (not a list)
  829. (Issue #2019).
  830. - ``group()`` now properly forwards keyword arguments (Issue #3426).
  831. Fix contributed by **Samuel Giffard**.
  832. - A ``chord`` where the header group only consists of a single task
  833. is now turned into a simple chain.
  834. - Passing a ``link`` argument to ``group.apply_async()`` now raises an error
  835. (Issue #3508).
  836. - ``chord | sig`` now attaches to the chord callback (Issue #3356).
  837. Periodic Tasks
  838. --------------
  839. New API for configuring periodic tasks
  840. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  841. This new API enables you to use signatures when defining periodic tasks,
  842. removing the chance of mistyping task names.
  843. An example of the new API is :ref:`here <beat-entries>`.
  844. .. :sha:`bc18d0859c1570f5eb59f5a969d1d32c63af764b`
  845. .. :sha:`132d8d94d38f4050db876f56a841d5a5e487b25b`
  846. Optimized Beat implementation
  847. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  848. The :program:`celery beat` implementation has been optimized
  849. for millions of periodic tasks by using a heap to schedule entries.
  850. Contributed by **Ask Solem** and **Alexander Koshelev**.
  851. Schedule tasks based on sunrise, sunset, dawn and dusk
  852. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  853. See :ref:`beat-solar` for more information.
  854. Contributed by **Mark Parncutt**.
  855. Result Backends
  856. ---------------
  857. RPC Result Backend matured
  858. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  859. Lots of bugs in the previously experimental RPC result backend have been fixed
  860. and can now be considered to production use.
  861. Contributed by **Ask Solem**, **Morris Tweed**.
  862. Redis: Result backend optimizations
  863. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  864. ``result.get()`` is now using pub/sub for streaming task results
  865. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  866. Calling ``result.get()`` when using the Redis result backend
  867. used to be extremely expensive as it was using polling to wait
  868. for the result to become available. A default polling
  869. interval of 0.5 seconds didn't help performance, but was
  870. necessary to avoid a spin loop.
  871. The new implementation is using Redis Pub/Sub mechanisms to
  872. publish and retrieve results immediately, greatly improving
  873. task round-trip times.
  874. Contributed by **Yaroslav Zhavoronkov** and **Ask Solem**.
  875. New optimized chord join implementation
  876. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  877. This was an experimental feature introduced in Celery 3.1,
  878. that could only be enabled by adding ``?new_join=1`` to the
  879. result backend URL configuration.
  880. We feel that the implementation has been tested thoroughly enough
  881. to be considered stable and enabled by default.
  882. The new implementation greatly reduces the overhead of chords,
  883. and especially with larger chords the performance benefit can be massive.
  884. New Riak result backend introduced
  885. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  886. See :ref:`conf-riak-result-backend` for more information.
  887. Contributed by **Gilles Dartiguelongue**, **Alman One** and **NoKriK**.
  888. New CouchDB result backend introduced
  889. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  890. See :ref:`conf-couchdb-result-backend` for more information.
  891. Contributed by **Nathan Van Gheem**.
  892. New Consul result backend introduced
  893. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  894. Add support for Consul as a backend using the Key/Value store of Consul.
  895. Consul has an HTTP API where through you can store keys with their values.
  896. The backend extends KeyValueStoreBackend and implements most of the methods.
  897. Mainly to set, get and remove objects.
  898. This allows Celery to store Task results in the K/V store of Consul.
  899. Consul also allows to set a TTL on keys using the Sessions from Consul. This way
  900. the backend supports auto expiry of Task results.
  901. For more information on Consul visit http://consul.io/
  902. The backend uses :pypi:`python-consul` for talking to the HTTP API.
  903. This package is fully Python 3 compliant just as this backend is:
  904. .. code-block:: console
  905. $ pip install python-consul
  906. That installs the required package to talk to Consul's HTTP API from Python.
  907. You can also specify consul as an extension in your dependency on Celery:
  908. .. code-block:: console
  909. $ pip install celery[consul]
  910. See :ref:`bundles` for more information.
  911. Contributed by **Wido den Hollander**.
  912. Brand new Cassandra result backend
  913. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  914. A brand new Cassandra backend utilizing the new :pypi:`cassandra-driver`
  915. library is replacing the old result backend using the older
  916. :pypi:`pycassa` library.
  917. See :ref:`conf-cassandra-result-backend` for more information.
  918. To depend on Celery with Cassandra as the result backend use:
  919. .. code-block:: console
  920. $ pip install celery[cassandra]
  921. You can also combine multiple extension requirements,
  922. please see :ref:`bundles` for more information.
  923. .. # XXX What changed?
  924. New Elasticsearch result backend introduced
  925. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  926. See :ref:`conf-elasticsearch-result-backend` for more information.
  927. To depend on Celery with Elasticsearch as the result bakend use:
  928. .. code-block:: console
  929. $ pip install celery[elasticsearch]
  930. You can also combine multiple extension requirements,
  931. please see :ref:`bundles` for more information.
  932. Contributed by **Ahmet Demir**.
  933. New File-system result backend introduced
  934. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  935. See :ref:`conf-filesystem-result-backend` for more information.
  936. Contributed by **Môshe van der Sterre**.
  937. Event Batching
  938. --------------
  939. Events are now buffered in the worker and sent as a list, reducing
  940. the overhead required to send monitoring events.
  941. For authors of custom event monitors there will be no action
  942. required as long as you're using the Python Celery
  943. helpers (:class:`~@events.Receiver`) to implement your monitor.
  944. However, if you're parsing raw event messages you must now account
  945. for batched event messages, as they differ from normal event messages
  946. in the following way:
  947. - The routing key for a batch of event messages will be set to
  948. ``<event-group>.multi`` where the only batched event group
  949. is currently ``task`` (giving a routing key of ``task.multi``).
  950. - The message body will be a serialized list-of-dictionaries instead
  951. of a dictionary. Each item in the list can be regarded
  952. as a normal event message body.
  953. .. :sha:`03399b4d7c26fb593e61acf34f111b66b340ba4e`
  954. In Other News...
  955. ----------------
  956. Requirements
  957. ~~~~~~~~~~~~
  958. - Now depends on :ref:`Kombu 4.0 <kombu:version-4.0>`.
  959. - Now depends on :pypi:`billiard` version 3.5.
  960. - No longer depends on :pypi:`anyjson`. Good-bye old friend :(
  961. Tasks
  962. ~~~~~
  963. - The "anon-exchange" is now used for simple name-name direct routing.
  964. This increases performance as it completely bypasses the routing table,
  965. in addition it also improves reliability for the Redis broker transport.
  966. - An empty ResultSet now evaluates to True.
  967. Fix contributed by **Colin McIntosh**.
  968. - The default routing key and exchange name is now taken from the
  969. :setting:`task_default_queue` setting.
  970. This means that to change the name of the default queue, you now
  971. only have to set a single setting.
  972. - New :setting:`task_reject_on_worker_lost` setting, and
  973. :attr:`~@Task.reject_on_worker_lost` task attribute decides what happens
  974. when the child worker process executing a late ack task is terminated.
  975. Contributed by **Michael Permana**.
  976. - ``Task.subtask`` renamed to ``Task.signature`` with alias.
  977. - ``Task.subtask_from_request`` renamed to
  978. ``Task.signature_from_request`` with alias.
  979. - The ``delivery_mode`` attribute for :class:`kombu.Queue` is now
  980. respected (Issue #1953).
  981. - Routes in :setting:`task-routes` can now specify a
  982. :class:`~kombu.Queue` instance directly.
  983. Example:
  984. .. code-block:: python
  985. task_routes = {'proj.tasks.add': {'queue': Queue('add')}}
  986. - ``AsyncResult`` now raises :exc:`ValueError` if task_id is None.
  987. (Issue #1996).
  988. - Retried tasks didn't forward expires setting (Issue #3297).
  989. - ``result.get()`` now supports an ``on_message`` argument to set a
  990. callback to be called for every message received.
  991. - New abstract classes added:
  992. - :class:`~celery.utils.abstract.CallableTask`
  993. Looks like a task.
  994. - :class:`~celery.utils.abstract.CallableSignature`
  995. Looks like a task signature.
  996. - ``Task.replace`` now properly forwards callbacks (Issue #2722).
  997. Fix contributed by **Nicolas Unravel**.
  998. - ``Task.replace``: Append to chain/chord (Closes #3232)
  999. Fixed issue #3232, adding the signature to the chain (if there's any).
  1000. Fixed the chord suppress if the given signature contains one.
  1001. Fix contributed by :github_user:`honux`.
  1002. - Task retry now also throws in eager mode.
  1003. Fix contributed by **Feanil Patel**.
  1004. Beat
  1005. ~~~~
  1006. - Fixed crontab infinite loop with invalid date.
  1007. When occurrence can never be reached (example, April, 31th), trying
  1008. to reach the next occurrence would trigger an infinite loop.
  1009. Try fixing that by raising a RuntimeError after 2,000 iterations
  1010. (Also added a test for crontab leap years in the process)
  1011. Fix contributed by **Romuald Brunet**.
  1012. - Now ensures the program exits with a non-zero exit code when an
  1013. exception terminates the service.
  1014. Fix contributed by **Simon Peeters**.
  1015. App
  1016. ~~~
  1017. - Dates are now always timezone aware even if
  1018. :setting:`enable_utc` is disabled (Issue #943).
  1019. Fix contributed by **Omer Katz**.
  1020. - **Config**: App preconfiguration is now also pickled with the configuration.
  1021. Fix contributed by **Jeremy Zafran**.
  1022. - The application can now change how task names are generated using
  1023. the :meth:`~@gen_task_name` method.
  1024. Contributed by **Dmitry Malinovsky**.
  1025. - App has new ``app.current_worker_task`` property that
  1026. returns the task that's currently being worked on (or :const:`None`).
  1027. (Issue #2100).
  1028. Logging
  1029. ~~~~~~~
  1030. - :func:`~celery.utils.log.get_task_logger` now raises an exception
  1031. if trying to use the name "celery" or "celery.task" (Issue #3475).
  1032. Execution Pools
  1033. ~~~~~~~~~~~~~~~
  1034. - **Eventlet/Gevent**: now enables AMQP heartbeat (Issue #3338).
  1035. - **Eventlet/Gevent**: Fixed race condition leading to "simultaneous read"
  1036. errors (Issue #2812).
  1037. - **Prefork**: Prefork pool now uses ``poll`` instead of ``select`` where
  1038. available (Issue #2373).
  1039. - **Prefork**: Fixed bug where the pool would refuse to shut down the
  1040. worker (Issue #2606).
  1041. - **Eventlet**: Now returns pool size in :program:`celery inspect stats`
  1042. command.
  1043. Contributed by **Alexander Oblovatniy**.
  1044. Testing
  1045. -------
  1046. - Celery is now a :pypi:`pytest` plugin, including fixtures
  1047. useful for unit and integration testing.
  1048. See the :ref:`testing user guide <testing>` for more information.
  1049. Transports
  1050. ~~~~~~~~~~
  1051. - ``amqps://`` can now be specified to require SSL.
  1052. - **Redis Transport**: The Redis transport now supports the
  1053. :setting:`broker_use_ssl` option.
  1054. Contributed by **Robert Kolba**.
  1055. - JSON serializer now calls ``obj.__json__`` for unsupported types.
  1056. This means you can now define a ``__json__`` method for custom
  1057. types that can be reduced down to a built-in json type.
  1058. Example:
  1059. .. code-block:: python
  1060. class Person:
  1061. first_name = None
  1062. last_name = None
  1063. address = None
  1064. def __json__(self):
  1065. return {
  1066. 'first_name': self.first_name,
  1067. 'last_name': self.last_name,
  1068. 'address': self.address,
  1069. }
  1070. - JSON serializer now handles datetimes, Django promise, UUID and Decimal.
  1071. - New ``Queue.consumer_arguments`` can be used for the ability to
  1072. set consumer priority via ``x-priority``.
  1073. See https://www.rabbitmq.com/consumer-priority.html
  1074. Example:
  1075. .. code-block:: python
  1076. consumer = Consumer(channel, consumer_arguments={'x-priority': 3})
  1077. - Queue/Exchange: ``no_declare`` option added (also enabled for
  1078. internal amq. exchanges).
  1079. Programs
  1080. ~~~~~~~~
  1081. - Celery is now using :mod:`argparse`, instead of :mod:`optparse`.
  1082. - All programs now disable colors if the controlling terminal is not a TTY.
  1083. - :program:`celery worker`: The ``-q`` argument now disables the startup
  1084. banner.
  1085. - :program:`celery worker`: The "worker ready" message is now logged
  1086. using severity info, instead of warn.
  1087. - :program:`celery multi`: ``%n`` format for is now synonym with
  1088. ``%N`` to be consistent with :program:`celery worker`.
  1089. - :program:`celery inspect`/:program:`celery control`: now supports a new
  1090. :option:`--json <celery inspect --json>` option to give output in json format.
  1091. - :program:`celery inspect registered`: now ignores built-in tasks.
  1092. - :program:`celery purge` now takes ``-Q`` and ``-X`` options
  1093. used to specify what queues to include and exclude from the purge.
  1094. - New :program:`celery logtool`: Utility for filtering and parsing
  1095. celery worker log-files
  1096. - :program:`celery multi`: now passes through `%i` and `%I` log
  1097. file formats.
  1098. - General: ``%p`` can now be used to expand to the full worker node-name
  1099. in log-file/pid-file arguments.
  1100. - A new command line option
  1101. :option:`--executable <celery worker --executable>` is now
  1102. available for daemonizing programs (:program:`celery worker` and
  1103. :program:`celery beat`).
  1104. Contributed by **Bert Vanderbauwhede**.
  1105. - :program:`celery worker`: supports new
  1106. :option:`--prefetch-multiplier <celery worker --prefetch-multiplier>` option.
  1107. Contributed by **Mickaël Penhard**.
  1108. - The ``--loader`` argument is now always effective even if an app argument is
  1109. set (Issue #3405).
  1110. - inspect/control now takes commands from registry
  1111. This means user remote-control commands can also be used from the
  1112. command-line.
  1113. Note that you need to specify the arguments/and type of arguments
  1114. for the arguments to be correctly passed on the command-line.
  1115. There are now two decorators, which use depends on the type of
  1116. command: `@inspect_command` + `@control_command`:
  1117. .. code-block:: python
  1118. from celery.worker.control import control_command
  1119. @control_command(
  1120. args=[('n', int)]
  1121. signature='[N=1]',
  1122. )
  1123. def something(state, n=1, **kwargs):
  1124. ...
  1125. Here ``args`` is a list of args supported by the command.
  1126. The list must contain tuples of ``(argument_name, type)``.
  1127. ``signature`` is just the command-line help used in e.g.
  1128. ``celery -A proj control --help``.
  1129. Commands also support `variadic` arguments, which means that any
  1130. arguments left over will be added to a single variable. Here demonstrated
  1131. by the ``terminate`` command which takes a signal argument and a variable
  1132. number of task_ids:
  1133. .. code-block:: python
  1134. from celery.worker.control import control_command
  1135. @control_command(
  1136. args=[('signal', str)],
  1137. signature='<signal> [id1, [id2, [..., [idN]]]]',
  1138. variadic='ids',
  1139. )
  1140. def terminate(state, signal, ids, **kwargs):
  1141. ...
  1142. This command can now be called using:
  1143. .. code-block:: console
  1144. $ celery -A proj control terminate SIGKILL id1 id2 id3`
  1145. See :ref:`worker-custom-control-commands` for more information.
  1146. Worker
  1147. ~~~~~~
  1148. - Improvements and fixes for :class:`~celery.utils.collections.LimitedSet`.
  1149. Getting rid of leaking memory + adding ``minlen`` size of the set:
  1150. the minimal residual size of the set after operating for some time.
  1151. ``minlen`` items are kept, even if they should've been expired.
  1152. Problems with older and even more old code:
  1153. #. Heap would tend to grow in some scenarios
  1154. (like adding an item multiple times).
  1155. #. Adding many items fast wouldn't clean them soon enough (if ever).
  1156. #. When talking to other workers, revoked._data was sent, but
  1157. it was processed on the other side as iterable.
  1158. That means giving those keys new (current)
  1159. time-stamp. By doing this workers could recycle
  1160. items forever. Combined with 1) and 2), this means that in
  1161. large set of workers, you're getting out of memory soon.
  1162. All those problems should be fixed now.
  1163. This should fix issues #3095, #3086.
  1164. Contributed by **David Pravec**.
  1165. - New settings to control remote control command queues.
  1166. - :setting:`control_queue_expires`
  1167. Set queue expiry time for both remote control command queues,
  1168. and remote control reply queues.
  1169. - :setting:`control_queue_ttl`
  1170. Set message time-to-live for both remote control command queues,
  1171. and remote control reply queues.
  1172. Contributed by **Alan Justino**.
  1173. - The :signal:`worker_shutdown` signal is now always called during shutdown.
  1174. Previously it would not be called if the worker instance was collected
  1175. by gc first.
  1176. - Worker now only starts the remote control command consumer if the
  1177. broker transport used actually supports them.
  1178. - Gossip now sets ``x-message-ttl`` for event queue to heartbeat_interval s.
  1179. (Issue #2005).
  1180. - Now preserves exit code (Issue #2024).
  1181. - Now rejects messages with an invalid ETA value (instead of ack, which means
  1182. they will be sent to the dead-letter exchange if one is configured).
  1183. - Fixed crash when the ``-purge`` argument was used.
  1184. - Log--level for unrecoverable errors changed from ``error`` to
  1185. ``critical``.
  1186. - Improved rate limiting accuracy.
  1187. - Account for missing timezone information in task expires field.
  1188. Fix contributed by **Albert Wang**.
  1189. - The worker no longer has a ``Queues`` bootsteps, as it is now
  1190. superfluous.
  1191. - Now emits the "Received task" line even for revoked tasks.
  1192. (Issue #3155).
  1193. - Now respects :setting:`broker_connection_retry` setting.
  1194. Fix contributed by **Nat Williams**.
  1195. - New :setting:`control_queue_ttl` and :setting:`control_queue_expires`
  1196. settings now enables you to configure remote control command
  1197. message TTLs, and queue expiry time.
  1198. Contributed by **Alan Justino**.
  1199. - New :data:`celery.worker.state.requests` enables O(1) loookup
  1200. of active/reserved tasks by id.
  1201. - Auto-scale didn't always update keep-alive when scaling down.
  1202. Fix contributed by **Philip Garnero**.
  1203. - Fixed typo ``options_list`` -> ``option_list``.
  1204. Fix contributed by **Greg Wilbur**.
  1205. - Some worker command-line arguments and ``Worker()`` class arguments have
  1206. been renamed for consistency.
  1207. All of these have aliases for backward compatibility.
  1208. - ``--send-events`` -> ``--task-events``
  1209. - ``--schedule`` -> ``--schedule-filename``
  1210. - ``--maxtasksperchild`` -> ``--max-tasks-per-child``
  1211. - ``Beat(scheduler_cls=)`` -> ``Beat(scheduler=)``
  1212. - ``Worker(send_events=True)`` -> ``Worker(task_events=True)``
  1213. - ``Worker(task_time_limit=)`` -> ``Worker(time_limit=``)
  1214. - ``Worker(task_soft_time_limit=)`` -> ``Worker(soft_time_limit=)``
  1215. - ``Worker(state_db=)`` -> ``Worker(statedb=)``
  1216. - ``Worker(working_directory=)`` -> ``Worker(workdir=)``
  1217. Debugging Utilities
  1218. ~~~~~~~~~~~~~~~~~~~
  1219. - :mod:`celery.contrib.rdb`: Changed remote debugger banner so that you can copy and paste
  1220. the address easily (no longer has a period in the address).
  1221. Contributed by **Jonathan Vanasco**.
  1222. - Fixed compatibility with recent :pypi:`psutil` versions (Issue #3262).
  1223. Signals
  1224. ~~~~~~~
  1225. - **App**: New signals for app configuration/finalization:
  1226. - :data:`app.on_configure <@on_configure>`
  1227. - :data:`app.on_after_configure <@on_after_configure>`
  1228. - :data:`app.on_after_finalize <@on_after_finalize>`
  1229. - **Task**: New task signals for rejected task messages:
  1230. - :data:`celery.signals.task_rejected`.
  1231. - :data:`celery.signals.task_unknown`.
  1232. - **Worker**: New signal for when a heartbeat event is sent.
  1233. - :data:`celery.signals.heartbeat_sent`
  1234. Contributed by **Kevin Richardson**.
  1235. Events
  1236. ~~~~~~
  1237. - Event messages now uses the RabbitMQ ``x-message-ttl`` option
  1238. to ensure older event messages are discarded.
  1239. The default is 5 seconds, but can be changed using the
  1240. :setting:`event_queue_ttl` setting.
  1241. - ``Task.send_event`` now automatically retries sending the event
  1242. on connection failure, according to the task publish retry settings.
  1243. - Event monitors now sets the :setting:`event_queue_expires`
  1244. setting by default.
  1245. The queues will now expire after 60 seconds after the monitor stops
  1246. consuming from it.
  1247. - Fixed a bug where a None value wasn't handled properly.
  1248. Fix contributed by **Dongweiming**.
  1249. - New :setting:`event_queue_prefix` setting can now be used
  1250. to change the default ``celeryev`` queue prefix for event receiver queues.
  1251. Contributed by **Takeshi Kanemoto**.
  1252. - ``State.tasks_by_type`` and ``State.tasks_by_worker`` can now be
  1253. used as a mapping for fast access to this information.
  1254. Deployment
  1255. ~~~~~~~~~~
  1256. - Generic init-scripts now support
  1257. :envvar:`CELERY_SU` and :envvar:`CELERYD_SU_ARGS` environment variables
  1258. to set the path and arguments for :command:`su` (:manpage:`su(1)`).
  1259. - Generic init-scripts now better support FreBSD and other BSD
  1260. systems by searching :file:`/usr/local/etc/` for the configuration file.
  1261. Contributed by **Taha Jahangir**.
  1262. - Generic init-script: Fixed strange bug for ``celerybeat`` where
  1263. restart didn't always work (Issue #3018).
  1264. - The systemd init script now uses a shell when executing
  1265. services.
  1266. Contributed by **Tomas Machalek**.
  1267. Result Backends
  1268. ~~~~~~~~~~~~~~~
  1269. - Redis: Now has a default socket timeout of 120 seconds.
  1270. The default can be changed using the new :setting:`redis_socket_timeout`
  1271. setting.
  1272. Contributed by **Raghuram Srinivasan**.
  1273. - RPC Backend result queues are now auto delete by default (Issue #2001).
  1274. - RPC Backend: Fixed problem where exception
  1275. wasn't deserialized properly with the json serializer (Issue #2518).
  1276. Fix contributed by **Allard Hoeve**.
  1277. - CouchDB: The backend used to double-json encode results.
  1278. Fix contributed by **Andrew Stewart**.
  1279. - CouchDB: Fixed typo causing the backend to not be found
  1280. (Issue #3287).
  1281. Fix contributed by **Andrew Stewart**.
  1282. - MongoDB: Now supports setting the :setting:`result_serialzier` setting
  1283. to ``bson`` to use the MongoDB libraries own serializer.
  1284. Contributed by **Davide Quarta**.
  1285. - MongoDB: URI handling has been improved to use
  1286. database name, user and password from the URI if provided.
  1287. Contributed by **Samuel Jaillet**.
  1288. - SQLAlchemy result backend: Now ignores all result
  1289. engine options when using NullPool (Issue #1930).
  1290. - SQLAlchemy result backend: Now sets max char size to 155 to deal
  1291. with brain damaged MySQL unicode implementation (Issue #1748).
  1292. - **General**: All Celery exceptions/warnings now inherit from common
  1293. :class:`~celery.exceptions.CeleryError`/:class:`~celery.exceptions.CeleryWarning`.
  1294. (Issue #2643).
  1295. Documentation Improvements
  1296. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1297. Contributed by:
  1298. - Adam Chainz
  1299. - Amir Rustamzadeh
  1300. - Arthur Vuillard
  1301. - Batiste Bieler
  1302. - Berker Peksag
  1303. - Bryce Groff
  1304. - Daniel Devine
  1305. - Edward Betts
  1306. - Jason Veatch
  1307. - Jeff Widman
  1308. - Maciej Obuchowski
  1309. - Manuel Kaufmann
  1310. - Maxime Beauchemin
  1311. - Mitchel Humpherys
  1312. - Pavlo Kapyshin
  1313. - Pierre Fersing
  1314. - Rik
  1315. - Tayfun Sen
  1316. - Wieland Hoffmann
  1317. Reorganization, Deprecations, and Removals
  1318. ==========================================
  1319. Incompatible changes
  1320. --------------------
  1321. - Prefork: Calling ``result.get()`` or joining any result from within a task
  1322. now raises :exc:`RuntimeError`.
  1323. In previous versions this would emit a warning.
  1324. - :mod:`celery.worker.consumer` is now a package, not a module.
  1325. - Module ``celery.worker.job`` renamed to :mod:`celery.worker.request`.
  1326. - Beat: ``Scheduler.Publisher``/``.publisher`` renamed to
  1327. ``.Producer``/``.producer``.
  1328. - Result: The task_name argument/attribute of :class:`@AsyncResult` was
  1329. removed.
  1330. This was historically a field used for :mod:`pickle` compatibility,
  1331. but is no longer needed.
  1332. - Backends: Arguments named ``status`` renamed to ``state``.
  1333. - Backends: ``backend.get_status()`` renamed to ``backend.get_state()``.
  1334. - Backends: ``backend.maybe_reraise()`` renamed to ``.maybe_throw()``
  1335. The promise API uses .throw(), so this change was made to make it more
  1336. consistent.
  1337. There's an alias available, so you can still use maybe_reraise until
  1338. Celery 5.0.
  1339. .. _v400-unscheduled-removals:
  1340. Unscheduled Removals
  1341. --------------------
  1342. - The experimental :mod:`celery.contrib.methods` feature has been removed,
  1343. as there were far many bugs in the implementation to be useful.
  1344. - The CentOS init-scripts have been removed.
  1345. These didn't really add any features over the generic init-scripts,
  1346. so you're encouraged to use them instead, or something like
  1347. :pypi:`supervisor`.
  1348. .. _v400-deprecations-reorg:
  1349. Reorganization Deprecations
  1350. ---------------------------
  1351. These symbols have been renamed, and while there's an alias available in this
  1352. version for backward compatibility, they will be removed in Celery 5.0, so
  1353. make sure you rename these ASAP to make sure it won't break for that release.
  1354. Chances are that you'll only use the first in this list, but you never
  1355. know:
  1356. - ``celery.utils.worker_direct`` ->
  1357. :meth:`celery.utils.nodenames.worker_direct`.
  1358. - ``celery.utils.nodename`` -> :meth:`celery.utils.nodenames.nodename`.
  1359. - ``celery.utils.anon_nodename`` ->
  1360. :meth:`celery.utils.nodenames.anon_nodename`.
  1361. - ``celery.utils.nodesplit`` -> :meth:`celery.utils.nodenames.nodesplit`.
  1362. - ``celery.utils.default_nodename`` ->
  1363. :meth:`celery.utils.nodenames.default_nodename`.
  1364. - ``celery.utils.node_format`` -> :meth:`celery.utils.nodenames.node_format`.
  1365. - ``celery.utils.host_format`` -> :meth:`celery.utils.nodenames.host_format`.
  1366. .. _v400-removals:
  1367. Scheduled Removals
  1368. ------------------
  1369. Modules
  1370. ~~~~~~~
  1371. - Module ``celery.worker.job`` has been renamed to :mod:`celery.worker.request`.
  1372. This was an internal module so shouldn't have any effect.
  1373. It's now part of the public API so must not change again.
  1374. - Module ``celery.task.trace`` has been renamed to ``celery.app.trace``
  1375. as the ``celery.task`` package is being phased out. The module
  1376. will be removed in version 5.0 so please change any import from::
  1377. from celery.task.trace import X
  1378. to::
  1379. from celery.app.trace import X
  1380. - Old compatibility aliases in the :mod:`celery.loaders` module
  1381. has been removed.
  1382. - Removed ``celery.loaders.current_loader()``, use: ``current_app.loader``
  1383. - Removed ``celery.loaders.load_settings()``, use: ``current_app.conf``
  1384. Result
  1385. ~~~~~~
  1386. - ``AsyncResult.serializable()`` and ``celery.result.from_serializable``
  1387. has been removed:
  1388. Use instead:
  1389. .. code-block:: pycon
  1390. >>> tup = result.as_tuple()
  1391. >>> from celery.result import result_from_tuple
  1392. >>> result = result_from_tuple(tup)
  1393. - Removed ``BaseAsyncResult``, use ``AsyncResult`` for instance checks
  1394. instead.
  1395. - Removed ``TaskSetResult``, use ``GroupResult`` instead.
  1396. - ``TaskSetResult.total`` -> ``len(GroupResult)``
  1397. - ``TaskSetResult.taskset_id`` -> ``GroupResult.id``
  1398. - Removed ``ResultSet.subtasks``, use ``ResultSet.results`` instead.
  1399. TaskSet
  1400. ~~~~~~~
  1401. TaskSet has been removed, as it was replaced by the ``group`` construct in
  1402. Celery 3.0.
  1403. If you have code like this:
  1404. .. code-block:: pycon
  1405. >>> from celery.task import TaskSet
  1406. >>> TaskSet(add.subtask((i, i)) for i in xrange(10)).apply_async()
  1407. You need to replace that with:
  1408. .. code-block:: pycon
  1409. >>> from celery import group
  1410. >>> group(add.s(i, i) for i in xrange(10))()
  1411. Events
  1412. ~~~~~~
  1413. - Removals for class :class:`celery.events.state.Worker`:
  1414. - ``Worker._defaults`` attribute.
  1415. Use ``{k: getattr(worker, k) for k in worker._fields}``.
  1416. - ``Worker.update_heartbeat``
  1417. Use ``Worker.event(None, timestamp, received)``
  1418. - ``Worker.on_online``
  1419. Use ``Worker.event('online', timestamp, received, fields)``
  1420. - ``Worker.on_offline``
  1421. Use ``Worker.event('offline', timestamp, received, fields)``
  1422. - ``Worker.on_heartbeat``
  1423. Use ``Worker.event('heartbeat', timestamp, received, fields)``
  1424. - Removals for class :class:`celery.events.state.Task`:
  1425. - ``Task._defaults`` attribute.
  1426. Use ``{k: getattr(task, k) for k in task._fields}``.
  1427. - ``Task.on_sent``
  1428. Use ``Worker.event('sent', timestamp, received, fields)``
  1429. - ``Task.on_received``
  1430. Use ``Task.event('received', timestamp, received, fields)``
  1431. - ``Task.on_started``
  1432. Use ``Task.event('started', timestamp, received, fields)``
  1433. - ``Task.on_failed``
  1434. Use ``Task.event('failed', timestamp, received, fields)``
  1435. - ``Task.on_retried``
  1436. Use ``Task.event('retried', timestamp, received, fields)``
  1437. - ``Task.on_succeeded``
  1438. Use ``Task.event('succeeded', timestamp, received, fields)``
  1439. - ``Task.on_revoked``
  1440. Use ``Task.event('revoked', timestamp, received, fields)``
  1441. - ``Task.on_unknown_event``
  1442. Use ``Task.event(short_type, timestamp, received, fields)``
  1443. - ``Task.update``
  1444. Use ``Task.event(short_type, timestamp, received, fields)``
  1445. - ``Task.merge``
  1446. Contact us if you need this.
  1447. Magic keyword arguments
  1448. ~~~~~~~~~~~~~~~~~~~~~~~
  1449. Support for the very old magic keyword arguments accepted by tasks is
  1450. finally removed in this version.
  1451. If you're still using these you have to rewrite any task still
  1452. using the old ``celery.decorators`` module and depending
  1453. on keyword arguments being passed to the task,
  1454. for example::
  1455. from celery.decorators import task
  1456. @task()
  1457. def add(x, y, task_id=None):
  1458. print('My task id is %r' % (task_id,))
  1459. should be rewritten into::
  1460. from celery import task
  1461. @task(bind=True)
  1462. def add(self, x, y):
  1463. print('My task id is {0.request.id}'.format(self))
  1464. Removed Settings
  1465. ----------------
  1466. The following settings have been removed, and is no longer supported:
  1467. Logging Settings
  1468. ~~~~~~~~~~~~~~~~
  1469. ===================================== =====================================
  1470. **Setting name** **Replace with**
  1471. ===================================== =====================================
  1472. ``CELERYD_LOG_LEVEL`` :option:`celery worker --loglevel`
  1473. ``CELERYD_LOG_FILE`` :option:`celery worker --logfile`
  1474. ``CELERYBEAT_LOG_LEVEL`` :option:`celery beat --loglevel`
  1475. ``CELERYBEAT_LOG_FILE`` :option:`celery beat --loglevel`
  1476. ``CELERYMON_LOG_LEVEL`` celerymon is deprecated, use flower
  1477. ``CELERYMON_LOG_FILE`` celerymon is deprecated, use flower
  1478. ``CELERYMON_LOG_FORMAT`` celerymon is deprecated, use flower
  1479. ===================================== =====================================
  1480. Task Settings
  1481. ~~~~~~~~~~~~~~
  1482. ===================================== =====================================
  1483. **Setting name** **Replace with**
  1484. ===================================== =====================================
  1485. ``CELERY_CHORD_PROPAGATES`` N/A
  1486. ===================================== =====================================
  1487. Changes to internal API
  1488. -----------------------
  1489. - Module ``celery.datastructures`` renamed to :mod:`celery.utils.collections`.
  1490. - Module ``celery.utils.timeutils`` renamed to :mod:`celery.utils.time`.
  1491. - ``celery.utils.datastructures.DependencyGraph`` moved to
  1492. :mod:`celery.utils.graph`.
  1493. - ``celery.utils.jsonify`` is now :func:`celery.utils.serialization.jsonify`.
  1494. - ``celery.utils.strtobool`` is now
  1495. :func:`celery.utils.serialization.strtobool`.
  1496. - ``celery.utils.is_iterable`` has been removed.
  1497. Instead use:
  1498. .. code-block:: python
  1499. isinstance(x, collections.Iterable)
  1500. - ``celery.utils.lpmerge`` is now :func:`celery.utils.collections.lpmerge`.
  1501. - ``celery.utils.cry`` is now :func:`celery.utils.debug.cry`.
  1502. - ``celery.utils.isatty`` is now :func:`celery.platforms.isatty`.
  1503. - ``celery.utils.gen_task_name`` is now
  1504. :func:`celery.utils.imports.gen_task_name`.
  1505. - ``celery.utils.deprecated`` is now :func:`celery.utils.deprecated.Callable`
  1506. - ``celery.utils.deprecated_property`` is now
  1507. :func:`celery.utils.deprecated.Property`.
  1508. - ``celery.utils.warn_deprecated`` is now :func:`celery.utils.deprecated.warn`
  1509. .. _v400-deprecations:
  1510. Deprecation Time-line Changes
  1511. =============================
  1512. See the :ref:`deprecation-timeline`.