whatsnew-4.0.rst 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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. Wall of Contributors
  33. --------------------
  34. Aaron McMillin, Adam Renberg, Adrien Guinet, Ahmet Demir, Aitor Gómez-Goiri,
  35. Albert Wang, Alex Koshelev, Alex Rattray, Alex Williams, Alexander Koshelev,
  36. Alexander Lebedev, Alexander Oblovatniy, Alexey Kotlyarov, Ali Bozorgkhan,
  37. Alice Zoë Bevan–McGregor, Allard Hoeve, Alman One, Andrea Rabbaglietti,
  38. Andrea Rosa, Andrei Fokau, Andrew Rodionoff, Andriy Yurchuk,
  39. Aneil Mallavarapu, Areski Belaid, Artyom Koval, Ask Solem, Balthazar Rouberol,
  40. Berker Peksag, Bert Vanderbauwhede, Brian Bouterse, Chris Duryee, Chris Erway,
  41. Chris Harris, Chris Martin, Corey Farwell, Craig Jellick, Cullen Rhodes,
  42. Dallas Marlow, Daniel Wallace, Danilo Bargen, Davanum Srinivas, Dave Smith,
  43. David Baumgold, David Harrigan, David Pravec, Dennis Brakhane, Derek Anderson,
  44. Dmitry Malinovsky, Dudás Ádám, Dustin J. Mitchell, Ed Morley, Fatih Sucu,
  45. Feanil Patel, Felix Schwarz, Fernando Rocha, Flavio Grossi, Frantisek Holop,
  46. Gao Jiangmiao, Gerald Manipon, Gilles Dartiguelongue, Gino Ledesma,
  47. Hank John, Hogni Gylfason, Ilya Georgievsky, Ionel Cristian Mărieș,
  48. James Pulec, Jared Lewis, Jason Veatch, Jasper Bryant-Greene, Jeremy Tillman,
  49. Jocelyn Delalande, Joe Jevnik, John Anderson, John Kirkham, John Whitlock,
  50. Joshua Harlow, Juan Rossi, Justin Patrin, Kai Groner, Kevin Harvey,
  51. Konstantinos Koukopoulos, Kouhei Maeda, Kracekumar Ramaraju,
  52. Krzysztof Bujniewicz, Latitia M. Haskins, Len Buckens, Lorenzo Mancini,
  53. Lucas Wiman, Luke Pomfrey, Marcio Ribeiro, Marin Atanasov Nikolov,
  54. Mark Parncutt, Maxime Vdb, Mher Movsisyan, Michael (michael-k),
  55. Michael Duane Mooring, Michael Permana, Mickaël Penhard, Mike Attwood,
  56. Morton Fox, Môshe van der Sterre, Nat Williams, Nathan Van Gheem, Nik Nyby,
  57. Omer Katz, Omer Korner, Ori Hoch, Paul Pearce, Paulo Bu, Philip Garnero,
  58. Piotr Maślanka, Radek Czajka, Raghuram Srinivasan, Randy Barlow,
  59. Rodolfo Carvalho, Roger Hu, Rongze Zhu, Ross Deane, Ryan Luckie,
  60. Rémy Greinhofer, Samuel Jaillet, Sergey Azovskov, Sergey Tikhonov,
  61. Seungha Kim, Steve Peak, Sukrit Khera, Tadej Janež, Tewfik Sadaoui,
  62. Thomas French, Thomas Grainger, Tobias Schottdorf, Tocho Tochev,
  63. Valentyn Klindukh, Vic Kumar, Vladimir Bolshakov, Vladimir Gorbunov,
  64. Wayne Chang, Wil Langford, Will Thompson, William King, Yury Selivanov,
  65. Zoran Pavlovic, 許邱翔, @allenling, @bee-keeper, @ffeast, @flyingfoxlee,
  66. @gdw2, @gitaarik, @hankjin, @m-vdb, @mdk, @nokrik, @ocean1, @orlo666,
  67. @raducc, @wanglei, @worldexception.
  68. .. _v400-important:
  69. Important Notes
  70. ===============
  71. Dropped support for Python 2.6
  72. ------------------------------
  73. Celery now requires Python 2.7 or later,
  74. and also drops support for Python 3.3 so supported versions are:
  75. - CPython 2.7
  76. - CPython 3.4
  77. - CPython 3.5
  78. - PyPy 4.0 (pypy2)
  79. - PyPy 2.4 (pypy3)
  80. - Jython 2.7.0
  81. Lowercase setting names
  82. -----------------------
  83. In the pursuit of beauty all settings have been renamed to be in all
  84. lowercase, and some setting names have been renamed for naming consistency.
  85. This change is fully backwards compatible so you can still use the uppercase
  86. setting names, but we would like you to upgrade as soon as possible and
  87. you can even do so automatically using the :program:`celery upgrade settings`
  88. command:
  89. .. code-block:: console
  90. $ celery upgrade settings proj/settings.py
  91. This command will modify your module in-place to use the new lower-case
  92. names (if you want uppercase with a celery prefix see block below),
  93. and save a backup in :file:`proj/settings.py.orig`.
  94. .. admonition:: For Django users and others who want to keep uppercase names
  95. If you're loading Celery configuration from the Django settings module
  96. then you will want to keep using the uppercase names.
  97. You will also want to use a ``CELERY_`` prefix so that no Celery settings
  98. collide with Django settings used by other apps.
  99. To do this, you will first need to convert your settings file
  100. to use the new consistent naming scheme, and add the prefix to all
  101. Celery related settings:
  102. .. code-block:: console
  103. $ celery upgrade settings --django proj/settings.py
  104. After upgrading the settings file, you need to set the prefix explicitly
  105. in your ``proj/celery.py`` module:
  106. .. code-block:: python
  107. app.config_from_object('django.conf:settings', namespace='CELERY')
  108. You can find the most up to date Django celery integration example
  109. here: :ref:`django-first-steps`.
  110. Note that this will also add a prefix to settings that didn't previously
  111. have one, like ``BROKER_URL``.
  112. Luckily you don't have to manually change the files, as
  113. the :program:`celery upgrade settings --django` program should do the
  114. right thing.
  115. The loader will try to detect if your configuration is using the new format,
  116. and act accordingly, but this also means that you are not allowed to mix and
  117. match new and old setting names, that is unless you provide a value for both
  118. alternatives.
  119. The major difference between previous versions, apart from the lower case
  120. names, are the renaming of some prefixes, like ``celerybeat_`` to ``beat_``,
  121. ``celeryd_`` to ``worker_``.
  122. The ``celery_`` prefix has also been removed, and task related settings
  123. from this namespace is now prefixed by ``task_``, worker related settings
  124. with ``worker_``.
  125. Apart from this most of the settings will be the same in lowercase, apart from
  126. a few special ones:
  127. ===================================== ==========================================================
  128. **Setting name** **Replace with**
  129. ===================================== ==========================================================
  130. ``CELERY_MAX_CACHED_RESULTS`` :setting:`result_cache_max`
  131. ``CELERY_MESSAGE_COMPRESSION`` :setting:`result_compression`/:setting:`task_compression`.
  132. ``CELERY_TASK_RESULT_EXPIRES`` :setting:`result_expires`
  133. ``CELERY_RESULT_DBURI`` :setting:`sqlalchemy_dburi`
  134. ``CELERY_RESULT_ENGINE_OPTIONS`` :setting:`sqlalchemy_engine_options`
  135. ``-*-_DB_SHORT_LIVED_SESSIONS`` :setting:`sqlalchemy_short_lived_sessions`
  136. ``CELERY_RESULT_DB_TABLE_NAMES`` :setting:`sqlalchemy_db_names`
  137. ``CELERY_ACKS_LATE`` :setting:`task_acks_late`
  138. ``CELERY_ALWAYS_EAGER`` :setting:`task_always_eager`
  139. ``CELERY_ANNOTATIONS`` :setting:`task_annotations`
  140. ``CELERY_MESSAGE_COMPRESSION`` :setting:`task_compression`
  141. ``CELERY_CREATE_MISSING_QUEUES`` :setting:`task_create_missing_queues`
  142. ``CELERY_DEFAULT_DELIVERY_MODE`` :setting:`task_default_delivery_mode`
  143. ``CELERY_DEFAULT_EXCHANGE`` :setting:`task_default_exchange`
  144. ``CELERY_DEFAULT_EXCHANGE_TYPE`` :setting:`task_default_exchange_type`
  145. ``CELERY_DEFAULT_QUEUE`` :setting:`task_default_queue`
  146. ``CELERY_DEFAULT_RATE_LIMIT`` :setting:`task_default_rate_limit`
  147. ``CELERY_DEFAULT_ROUTING_KEY`` :setting:`task_default_routing_key`
  148. ``-"-_EAGER_PROPAGATES_EXCEPTIONS`` :setting:`task_eager_propagates`
  149. ``CELERY_IGNORE_RESULT`` :setting:`task_ignore_result`
  150. ``CELERY_TASK_PUBLISH_RETRY`` :setting:`task_publish_retry`
  151. ``CELERY_TASK_PUBLISH_RETRY_POLICY`` :setting:`task_publish_retry_policy`
  152. ``CELERY_QUEUES`` :setting:`task_queues`
  153. ``CELERY_ROUTES`` :setting:`task_routes`
  154. ``CELERY_SEND_TASK_ERROR_EMAILS`` :setting:`task_send_error_emails`
  155. ``CELERY_SEND_TASK_SENT_EVENT`` :setting:`task_send_sent_event`
  156. ``CELERY_TASK_SERIALIZER`` :setting:`task_serializer`
  157. ``CELERYD_TASK_SOFT_TIME_LIMIT`` :setting:`task_soft_time_limit`
  158. ``CELERYD_TASK_TIME_LIMIT`` :setting:`task_time_limit`
  159. ``CELERY_TRACK_STARTED`` :setting:`task_track_started`
  160. ``CELERY_DISABLE_RATE_LIMITS`` :setting:`worker_disable_rate_limits`
  161. ``CELERY_ENABLE_REMOTE_CONTROL`` :setting:`worker_enable_remote_control`
  162. ``CELERYD_SEND_EVENTS`` :setting:`worker_send_task_events`
  163. ===================================== ==========================================================
  164. You can see a full table of the changes in :ref:`conf-old-settings-map`.
  165. JSON is now the default serializer
  166. ----------------------------------
  167. The time has finally come to end the reign of :mod:`pickle` as the default
  168. serialization mechanism, and json is the default serializer starting from this
  169. version.
  170. This change was :ref:`announced with the release of Celery 3.1
  171. <last-version-to-enable-pickle>`.
  172. If you're still depending on :mod:`pickle` being the default serializer,
  173. then you have to configure your app before upgrading to 4.0:
  174. .. code-block:: python
  175. task_serializer = 'pickle'
  176. result_serializer = 'pickle'
  177. accept_content = {'pickle'}
  178. The Task base class no longer automatically register tasks
  179. ----------------------------------------------------------
  180. The :class:`~@Task` class is no longer using a special metaclass
  181. that automatically registers the task in the task registry.
  182. Instead this is now handled by the :class:`@task` decorators.
  183. If you're still using class based tasks, then you need to register
  184. these manually:
  185. .. code-block:: python
  186. class CustomTask(Task):
  187. def run(self):
  188. print('running')
  189. app.tasks.register(CustomTask())
  190. The best practice is to use custom task classes only for overriding
  191. general behavior, and then using the task decorator to realize the task:
  192. .. code-block:: python
  193. @app.task(bind=True, base=CustomTask)
  194. def custom(self):
  195. print('running')
  196. This change also means the ``abstract`` attribute of the task
  197. no longer has any effect.
  198. Task argument checking
  199. ----------------------
  200. The arguments of the task is now verified when calling the task,
  201. even asynchronously:
  202. .. code-block:: pycon
  203. >>> @app.task
  204. ... def add(x, y):
  205. ... return x + y
  206. >>> add.delay(8, 8)
  207. <AsyncResult: f59d71ca-1549-43e0-be41-4e8821a83c0c>
  208. >>> add.delay(8)
  209. Traceback (most recent call last):
  210. File "<stdin>", line 1, in <module>
  211. File "celery/app/task.py", line 376, in delay
  212. return self.apply_async(args, kwargs)
  213. File "celery/app/task.py", line 485, in apply_async
  214. check_arguments(*(args or ()), **(kwargs or {}))
  215. TypeError: add() takes exactly 2 arguments (1 given)
  216. Redis Events not backward compatible
  217. ------------------------------------
  218. The Redis ``fanout_patterns`` and ``fanout_prefix`` transport
  219. options are now enabled by default, which means that workers
  220. running 4.0 cannot see workers running 3.1 on the default configuration,
  221. and vice versa.
  222. This is only related to monitor event messages, the workers should still
  223. execute tasks as normally.
  224. You can avoid this situation by configuring the 3.1 workers (and clients)
  225. to enable these settings, before upgrading to 4.0:
  226. .. code-block:: python
  227. BROKER_TRANSPORT_OPTIONS = {
  228. 'fanout_patterns': True,
  229. 'fanout_prefix': True,
  230. }
  231. Django: Autodiscover now supports Django app configs
  232. ----------------------------------------------------
  233. The :meth:`@autodiscover` function can now be called without arguments,
  234. and the Django handler will automatically find your installed apps:
  235. .. code-block:: python
  236. app.autodiscover()
  237. The Django integration :ref:`example in the documentation
  238. <django-first-steps>` has been updated to use the argument-less call.
  239. Worker direct queues no longer use auto-delete.
  240. ===============================================
  241. Workers/clients running 4.0 will no longer be able to send
  242. worker direct messages to worker running older versions, and vice versa.
  243. If you're relying on worker direct messages you should upgrade
  244. your 3.x workers and clients to use the new routing settings first,
  245. by replacing :func:`celery.utils.worker_direct` with this implementation:
  246. .. code-block:: python
  247. from kombu import Exchange, Queue
  248. worker_direct_exchange = Exchange('C.dq2')
  249. def worker_direct(hostname):
  250. return Queue(
  251. '{hostname}.dq2'.format(hostname),
  252. exchange=worker_direct_exchange,
  253. routing_key=hostname,
  254. )
  255. (This feature closed Issue #2492.)
  256. Old command-line programs removed
  257. ---------------------------------
  258. Installing Celery will no longer install the ``celeryd``,
  259. ``celerybeat`` and ``celeryd-multi`` programs.
  260. This was announced with the release of Celery 3.1, but you may still
  261. have scripts pointing to the old names so make sure you update these
  262. to use the new umbrella command:
  263. +-------------------+--------------+-------------------------------------+
  264. | Program | New Status | Replacement |
  265. +===================+==============+=====================================+
  266. | ``celeryd`` | **REMOVED** | :program:`celery worker` |
  267. +-------------------+--------------+-------------------------------------+
  268. | ``celerybeat`` | **REMOVED** | :program:`celery beat` |
  269. +-------------------+--------------+-------------------------------------+
  270. | ``celeryd-multi`` | **REMOVED** | :program:`celery multi` |
  271. +-------------------+--------------+-------------------------------------+
  272. .. _v400-news:
  273. News
  274. ====
  275. New Task Message Protocol
  276. =========================
  277. # e71652d384b1b5df2a4e6145df9f0efb456bc71c
  278. This version introduces a brand new task message protocol,
  279. the first major change to the protocol since the beginning of the project.
  280. The new protocol is backwards incompatible, so you need to set
  281. the :setting:`task_protocol` configuration option to ``2`` to take advantage:
  282. .. code-block:: python
  283. app = Celery()
  284. app.conf.task_protocol = 2
  285. Using the new protocol is recommended for everybody who don't
  286. need backwards compatibility.
  287. Once enabled task messages sent is unreadable to older versions of Celery.
  288. New protocol highlights
  289. -----------------------
  290. The new protocol fixes many problems with the old one, and enables
  291. some long-requested features:
  292. - Most of the data are now sent as message headers, instead of being
  293. serialized with the message body.
  294. In version 1 of the protocol the worker always had to deserialize
  295. the message to be able to read task metadata like the task id,
  296. name, etc. This also meant that the worker was forced to double-decode
  297. the data, first deserializing the message on receipt, serializing
  298. the message again to send to child process, then finally the child process
  299. deserializes the message again.
  300. Keeping the metadata fields in the message headers means the worker
  301. does not actually have to decode the payload before delivering
  302. the task to the child process, and also that it's now possible
  303. for the worker to reroute a task written in a language different
  304. from Python to a different worker.
  305. - A new ``lang`` message header can be used to specify the programming
  306. language the task is written in.
  307. - Worker stores results for internal errors like ``ContentDisallowed``,
  308. and other deserialization errors.
  309. - Worker stores results and sends monitoring events for unregistered
  310. task errors.
  311. - Worker calls callbacks/errbacks even when the result is sent by the
  312. parent process (e.g. :exc:`WorkerLostError` when a child process
  313. terminates, deserialization errors, unregistered tasks).
  314. - A new ``origin`` header contains information about the process sending
  315. the task (worker nodename, or pid and hostname information).
  316. - A new ``shadow`` header allows you to modify the task name used in logs.
  317. This is useful for dispatch like patterns, like a task that calls
  318. any function using pickle (don't do this at home):
  319. .. code-block:: python
  320. from celery import Task
  321. from celery.utils.imports import qualname
  322. class call_as_task(Task):
  323. def shadow_name(self, args, kwargs, options):
  324. return 'call_as_task:{0}'.format(qualname(args[0]))
  325. def run(self, fun, *args, **kwargs):
  326. return fun(*args, **kwargs)
  327. call_as_task = app.tasks.register(call_as_task())
  328. - New ``argsrepr`` and ``kwargsrepr`` fields contain textual representations
  329. of the task arguments (possibly truncated) for use in logs, monitors, etc.
  330. This means the worker does not have to deserialize the message payload
  331. to display the task arguments for informational purposes.
  332. - Chains now use a dedicated ``chain`` field enabling support for chains
  333. of thousands and more tasks.
  334. - New ``parent_id`` and ``root_id`` headers adds information about
  335. a tasks relationship with other tasks.
  336. - ``parent_id`` is the task id of the task that called this task
  337. - ``root_id`` is the first task in the workflow.
  338. These fields can be used to improve monitors like flower to group
  339. related messages together (like chains, groups, chords, complete
  340. workflows, etc).
  341. - ``app.TaskProducer`` replaced by :meth:`@amqp.create_task_message`` and
  342. :meth:`@amqp.send_task_message``.
  343. Dividing the responsibilities into creating and sending means that
  344. people who want to send messages using a Python amqp client directly,
  345. does not have to implement the protocol.
  346. The :meth:`@amqp.create_task_message` method calls either
  347. :meth:`@amqp.as_task_v2`, or :meth:`@amqp.as_task_v1` depending
  348. on the configured task protocol, and returns a special
  349. :class:`~celery.app.amqp.task_message` tuple containing the
  350. headers, properties and body of the task message.
  351. .. seealso::
  352. The new task protocol is documented in full here:
  353. :ref:`message-protocol-task-v2`.
  354. Prefork: Tasks now log from the child process
  355. =============================================
  356. Logging of task success/failure now happens from the child process
  357. actually executing the task, which means that logging utilities
  358. like Sentry can get full information about tasks that fail, including
  359. variables in the traceback.
  360. Prefork: One logfile per child process
  361. ======================================
  362. Init scrips and :program:`celery multi` now uses the `%I` log file format
  363. option (e.g. :file:`/var/log/celery/%n%I.log`).
  364. This change was necessary to ensure each child
  365. process has a separate log file after moving task logging
  366. to the child process, as multiple processes writing to the same
  367. log file can cause corruption.
  368. You are encouraged to upgrade your init scripts and multi arguments
  369. to use this new option.
  370. Configure broker URL for read/write separately.
  371. ===============================================
  372. New :setting:`broker_read_url` and :setting:`broker_write_url` settings
  373. have been added so that separate broker urls can be provided
  374. for connections used for consuming/publishing.
  375. In addition to the configuration options, two new methods have been
  376. added the app API:
  377. - ``app.connection_for_read()``
  378. - ``app.connection_for_write()``
  379. These should now be used in place of ``app.connection()`` to specify
  380. the intent of the required connection.
  381. .. note::
  382. Two connection pools are available: ``app.pool`` (read), and
  383. ``app.producer_pool`` (write). The latter does not actually give connections
  384. but full :class:`kombu.Producer` instances.
  385. .. code-block:: python
  386. def publish_some_message(app, producer=None):
  387. with app.producer_or_acquire(producer) as producer:
  388. ...
  389. def consume_messages(app, connection=None):
  390. with app.connection_or_acquire(connection) as connection:
  391. ...
  392. Canvas Refactor
  393. ===============
  394. The canvas/workflow implementation have been heavily refactored
  395. to fix some long outstanding issues.
  396. # BLALBLABLA
  397. d79dcd8e82c5e41f39abd07ffed81ca58052bcd2
  398. 1e9dd26592eb2b93f1cb16deb771cfc65ab79612
  399. e442df61b2ff1fe855881c1e2ff9acc970090f54
  400. 0673da5c09ac22bdd49ba811c470b73a036ee776
  401. - Now unrolls groups within groups into a single group (Issue #1509).
  402. - chunks/map/starmap tasks now routes based on the target task
  403. - chords and chains can now be immutable.
  404. - Fixed bug where serialized signatures were not converted back into
  405. signatures (Issue #2078)
  406. Fix contributed by Ross Deane.
  407. - Fixed problem where chains and groups did not work when using JSON
  408. serialization (Issue #2076).
  409. Fix contributed by Ross Deane.
  410. - Creating a chord no longer results in multiple values for keyword
  411. argument 'task_id' (Issue #2225).
  412. Fix contributed by Aneil Mallavarapu
  413. - Fixed issue where the wrong result is returned when a chain
  414. contains a chord as the penultimate task.
  415. Fix contributed by Aneil Mallavarapu
  416. - Special case of ``group(A.s() | group(B.s() | C.s()))`` now works.
  417. - Chain: Fixed bug with incorrect id set when a subtask is also a chain.
  418. - ``group | group`` is now flattened into a single group (Issue #2573).
  419. - Fixed issue where ``group | task`` was not upgrading correctly
  420. to chord (Issue #2922).
  421. Amazon SQS transport now officially supported.
  422. ==============================================
  423. The SQS broker transport has been rewritten to use async I/O and as such
  424. joins RabbitMQ and Redis as officially supported transports.
  425. The new implementation also takes advantage of long polling,
  426. and closes several issues related to using SQS as a broker.
  427. This work was sponsored by Nextdoor.
  428. Schedule tasks based on sunrise, sunset, dawn and dusk.
  429. =======================================================
  430. See :ref:`beat-solar` for more information.
  431. Contributed by Mark Parncutt.
  432. New API for configuring periodic tasks
  433. ======================================
  434. This new API enables you to use signatures when defining periodic tasks,
  435. removing the chance of mistyping task names.
  436. An example of the new API is :ref:`here <beat-entries>`.
  437. # bc18d0859c1570f5eb59f5a969d1d32c63af764b
  438. # 132d8d94d38f4050db876f56a841d5a5e487b25b
  439. RabbitMQ Priority queue support
  440. ===============================
  441. See :ref:`routing-options-rabbitmq-priorities` for more information.
  442. Contributed by Gerald Manipon.
  443. Prefork: Limit child process resident memory size.
  444. ==================================================
  445. # 5cae0e754128750a893524dcba4ae030c414de33
  446. You can now limit the maximum amount of memory allocated per prefork
  447. pool child process by setting the worker
  448. :option:`--maxmemperchild <celery worker --maxmemperchild>` option,
  449. or the :setting:`worker_max_memory_per_child` setting.
  450. The limit is for RSS/resident memory size and is specified in kilobytes.
  451. A child process having exceeded the limit will be terminated and replaced
  452. with a new process after the currently executing task returns.
  453. See :ref:`worker-maxmemperchild` for more information.
  454. Contributed by Dave Smith.
  455. Redis: Result backend optimizations
  456. ===============================================
  457. RPC is now using pub/sub for streaming task results.
  458. ----------------------------------------------------
  459. Calling ``result.get()`` when using the Redis result backend
  460. used to be extremely expensive as it was using polling to wait
  461. for the result to become available. A default polling
  462. interval of 0.5 seconds did not help performance, but was
  463. necessary to avoid a spin loop.
  464. The new implementation is using Redis Pub/Sub mechanisms to
  465. publish and retrieve results immediately, greatly improving
  466. task round-trip times.
  467. Contributed by Yaroslav Zhavoronkov and Ask Solem.
  468. New optimized chord join implementation.
  469. ----------------------------------------
  470. This was an experimental feature introduced in Celery 3.1,
  471. that could only be enabled by adding ``?new_join=1`` to the
  472. result backend URL configuration.
  473. We feel that the implementation has been tested thoroughly enough
  474. to be considered stable and enabled by default.
  475. The new implementation greatly reduces the overhead of chords,
  476. and especially with larger chords the performance benefit can be massive.
  477. New Riak result backend Introduced.
  478. ===================================
  479. See :ref:`conf-riak-result-backend` for more information.
  480. Contributed by Gilles Dartiguelongue, Alman One and NoKriK.
  481. New CouchDB result backend introduced.
  482. ======================================
  483. See :ref:`conf-couchdb-result-backend` for more information.
  484. Contributed by Nathan Van Gheem
  485. Brand new Cassandra result backend.
  486. ===================================
  487. A brand new Cassandra backend utilizing the new :pypi:`cassandra-driver`
  488. library is replacing the old result backend which was using the older
  489. :pypi:`pycassa` library.
  490. See :ref:`conf-cassandra-result-backend` for more information.
  491. # XXX What changed?
  492. New Elasticsearch result backend introduced.
  493. ============================================
  494. See :ref:`conf-elasticsearch-result-backend` for more information.
  495. Contributed by Ahmet Demir.
  496. New Filesystem result backend introduced.
  497. =========================================
  498. See :ref:`conf-filesystem-result-backend` for more information.
  499. Contributed by Môshe van der Sterre.
  500. Event Batching
  501. ==============
  502. Events are now buffered in the worker and sent as a list which reduces
  503. the overhead required to send monitoring events.
  504. For authors of custom event monitors there will be no action
  505. required as long as you're using the Python celery
  506. helpers (:class:`~@events.Receiver`) to implement your monitor.
  507. However, if you're manually receiving event messages you must now account
  508. for batched event messages which differ from normal event messages
  509. in the following way:
  510. - The routing key for a batch of event messages will be set to
  511. ``<event-group>.multi`` where the only batched event group
  512. is currently ``task`` (giving a routing key of ``task.multi``).
  513. - The message body will be a serialized list-of-dictionaries instead
  514. of a dictionary. Each item in the list can be regarded
  515. as a normal event message body.
  516. 03399b4d7c26fb593e61acf34f111b66b340ba4e
  517. Task.replace
  518. ============
  519. Task.replace changed, removes Task.replace_in_chord.
  520. The two methods had almost the same functionality, but the old Task.replace
  521. would force the new task to inherit the callbacks/errbacks of the existing
  522. task.
  523. If you replace a node in a tree, then you would not expect the new node to
  524. inherit the children of the old node, so this seems like unexpected
  525. behavior.
  526. So self.replace(sig) now works for any task, in addition sig can now
  527. be a group.
  528. Groups are automatically converted to a chord, where the callback
  529. will "accumulate" the results of the group tasks.
  530. A new builtin task (`celery.accumulate` was added for this purpose)
  531. Closes #817
  532. Optimized Beat implementation
  533. =============================
  534. The :program:`celery beat` implementation has been optimized
  535. for millions of periodic tasks by using a heap to schedule entries.
  536. Contributed by Ask Solem and Alexander Koshelev.
  537. Task Autoretry Decorator
  538. ========================
  539. Writing custom retry handling for exception events is so common
  540. that we now have built-in support for it.
  541. For this a new ``autoretry_for`` argument is now supported by
  542. the task decorators, where you can specify a tuple of exceptions
  543. to automatically retry for.
  544. See :ref:`task-autoretry` for more information.
  545. Contributed by Dmitry Malinovsky.
  546. # 75246714dd11e6c463b9dc67f4311690643bff24
  547. Remote Task Tracebacks
  548. ======================
  549. The new :setting:`task_remote_tracebacks` will make task tracebacks more
  550. useful by injecting the stack of the remote worker.
  551. This feature requires the additional :pypi:`tblib` library.
  552. Contributed by Ionel Cristian Mărieș.
  553. Async Result API
  554. ================
  555. eventlet/gevent drainers, promises, BLA BLA
  556. Closed issue #2529.
  557. In Other News
  558. -------------
  559. - **Requirements**:
  560. - Now depends on :ref:`Kombu 4.0 <kombu:version-4.0>`.
  561. - Now depends on :pypi:`billiard` version 3.5.
  562. - No longer depends on :pypi:`anyjson` :sadface:
  563. - **Tasks**: The "anon-exchange" is now used for simple name-name direct routing.
  564. This increases performance as it completely bypasses the routing table,
  565. in addition it also improves reliability for the Redis broker transport.
  566. - **Tasks**: :setting:`task_routes` can now contain glob patterns and
  567. regexes.
  568. See new examples in :setting:`task_routes` and :ref:`routing-automatic`.
  569. - **Eventlet/Gevent**: Fixed race condition leading to "simultaneous read"
  570. errors (Issue #2812).
  571. - **Programs**: ``%n`` format for :program:`celery multi` is now synonym with
  572. ``%N`` to be consistent with :program:`celery worker`.
  573. - **Programs**: celery inspect/control now supports a new
  574. :option:`--json <celery inspect --json>` option to give output in json format.
  575. - **Programs**: :program:`celery inspect registered` now ignores built-in
  576. tasks.
  577. - **Programs**: New :program:`celery logtool`: Utility for filtering and parsing
  578. celery worker logfiles
  579. - **Redis Transport**: The Redis transport now supports the
  580. :setting:`broker_use_ssl` option.
  581. - **Worker**: Worker now only starts the remote control command consumer if the
  582. broker transport used actually supports them.
  583. - **Worker**: Gossip now sets ``x-message-ttl`` for event queue to heartbeat_interval s.
  584. (Issue #2005).
  585. - **Worker**: Now preserves exit code (Issue #2024).
  586. - **Worker**: Loglevel for unrecoverable errors changed from ``error`` to
  587. ``critical``.
  588. - **Worker**: Improved rate limiting accuracy.
  589. - **Worker**: Account for missing timezone information in task expires field.
  590. Fix contributed by Albert Wang.
  591. - **Worker**: The worker no longer has a ``Queues`` bootsteps, as it is now
  592. superfluous.
  593. - **Tasks**: New :setting:`task_reject_on_worker_lost` setting, and
  594. :attr:`~@Task.reject_on_worker_lost` task attribute decides what happens
  595. when the child worker process executing a late ack task is terminated.
  596. Contributed by Michael Permana.
  597. - **Worker**: Improvements and fixes for LimitedSet
  598. Getting rid of leaking memory + adding minlen size of the set
  599. minlen is minimal residual size of set after operating for long.
  600. Minlen items are kept, even if they should be expired by time, until
  601. we get newer items.
  602. Problems with older and even more old code:
  603. 1)
  604. Heap would tend to grow in some scenarios
  605. (like adding an item multiple times).
  606. 2) Adding many items fast would not clean them soon enough (if ever).
  607. 3) When talking to other workers, revoked._data was sent, but
  608. it was processed on the other side as iterable.
  609. That means giving those keys new (current)
  610. timestamp. By doing this workers could recycle
  611. items forever. Combined with 1) and 2), this means that in
  612. large set of workers, you are getting out of memory soon.
  613. All those problems should be fixed now,
  614. also some new unittests are added.
  615. This should fix issues #3095, #3086.
  616. Contributed by David Pravec.
  617. - **App**: New signals for app configuration/finalization:
  618. - :data:`app.on_configure <@on_configure>`
  619. - :data:`app.on_after_configure <@on_after_configure>`
  620. - :data:`app.on_after_finalize <@on_after_finalize>`
  621. - **Task**: New task signals for rejected task messages:
  622. - :data:`celery.signals.task_rejected`.
  623. - :data:`celery.signals.task_unknown`.
  624. - **Events**: Event messages now uses the RabbitMQ ``x-message-ttl`` option
  625. to ensure older event messages are discarded.
  626. The default is 5 seconds, but can be changed using the
  627. :setting:`event_queue_ttl` setting.
  628. - **Events**: Event monitors now sets the :setting:`event_queue_expires`
  629. setting by default.
  630. The queues will now expire after 60 seconds after the monitor stops
  631. consuming from it.
  632. - **Canvas**: ``chunks``/``map``/``starmap`` are now routed based on the target task.
  633. - **Canvas**: ``Signature.link`` now works when argument is scalar (not a list)
  634. (Issue #2019).
  635. - **App**: The application can now change how task names are generated using
  636. the :meth:`~@gen_task_name` method.
  637. Contributed by Dmitry Malinovsky.
  638. - **App**: App has new ``app.current_worker_task`` property that
  639. returns the task that is currently being worked on (or :const:`None`).
  640. (Issue #2100).
  641. - **Tasks**: ``Task.subtask`` renamed to ``Task.signature`` with alias.
  642. - **Tasks**: ``Task.subtask_from_request`` renamed to
  643. ``Task.signature_from_request`` with alias.
  644. - **Tasks**: The ``delivery_mode`` attribute for :class:`kombu.Queue` is now
  645. respected (Issue #1953).
  646. - **Tasks**: Routes in :setting:`task-routes` can now specify a
  647. :class:`~kombu.Queue` instance directly.
  648. Example:
  649. .. code-block:: python
  650. task_routes = {'proj.tasks.add': {'queue': Queue('add')}}
  651. - **Tasks**: ``AsyncResult`` now raises :exc:`ValueError` if task_id is None.
  652. (Issue #1996).
  653. - **Tasks**: ``result.get()`` now supports an ``on_message`` argument to set a
  654. callback to be called for every message received.
  655. - **Tasks**: New abstract classes added:
  656. - :class:`~celery.utils.abstract.CallableTask`
  657. Looks like a task.
  658. - :class:`~celery.utils.abstract.CallableSignature`
  659. Looks like a task signature.
  660. - **Programs**: :program:`celery multi` now passes through `%i` and `%I` log
  661. file formats.
  662. - **Programs**: ``%p`` can now be used to expand to the full worker nodename
  663. in logfile/pidfile arguments.
  664. - **Programs**: A new command line option
  665. :option:`--executable <celery worker --executable>` is now
  666. available for daemonizing programs (:program:`celery worker` and
  667. :program:`celery beat`).
  668. Contributed by Bert Vanderbauwhede.
  669. - **Programs**: :program:`celery worker` supports new
  670. :option:`--prefetch-multiplier <celery worker --prefetch-multiplier>` option.
  671. Contributed by Mickaël Penhard.
  672. - **Deployment**: Generic init scripts now support
  673. :envvar:`CELERY_SU`` and :envvar:`CELERYD_SU_ARGS` environment variables
  674. to set the path and arguments for :command:`su` (:manpage:`su(1)`).
  675. - **Prefork**: Prefork pool now uses ``poll`` instead of ``select`` where
  676. available (Issue #2373).
  677. - **Eventlet**: Now returns pool size in :program:`celery inspect stats`
  678. command.
  679. Contributed by Alexander Oblovatniy.
  680. - **Tasks**: New :setting:`email_charset` setting allows for changing
  681. the charset used for outgoing error emails.
  682. Contributed by Vladimir Gorbunov.
  683. - **Worker**: Now respects :setting:`broker_connection_retry` setting.
  684. Fix contributed by Nat Williams.
  685. - **Worker**: Autoscale did not always update keepalive when scaling down.
  686. Fix contributed by Philip Garnero.
  687. - **General**: Dates are now always timezone aware even if
  688. :setting:`enable_utc` is disabled (Issue #943).
  689. Fix contributed by Omer Katz.
  690. - **Result Backends**: The redis result backend now has a default socket
  691. timeout of 5 seconds.
  692. The default can be changed using the new :setting:`redis_socket_timeout`
  693. setting.
  694. Contributed by Raghuram Srinivasan.
  695. - **Result Backends**: RPC Backend result queues are now auto delete by
  696. default (Issue #2001).
  697. - **Result Backends**: MongoDB now supports setting the
  698. :setting:`result_serialzier` setting to ``bson`` to use the MongoDB
  699. libraries own serializer.
  700. Contributed by Davide Quarta.
  701. - **Result Backends**: SQLAlchemy result backend now ignores all result
  702. engine options when using NullPool (Issue #1930).
  703. - **Result Backends**: MongoDB URI handling has been improved to use
  704. database name, user and password from the URI if provided.
  705. Contributed by Samuel Jaillet.
  706. - **Result Backends**: Fix problem with rpc/amqp backends where exception
  707. was not deserialized properly with the json serializer (Issue #2518).
  708. Fix contributed by Allard Hoeve.
  709. - **Result Backends**: Database backend now sets max char size to 155 to deal
  710. with brain damaged MySQL unicode implementation (Issue #1748).
  711. - **General**: All Celery exceptions/warnings now inherit from common
  712. :class:`~celery.exceptions.CeleryException`/:class:`~celery.exceptions.CeleryWarning`.
  713. (Issue #2643).
  714. - **Tasks**: Task retry now also throws in eager mode.
  715. Fix contributed by Feanil Patel.
  716. - **Tasks**: Task error email charset now set to ``utf-8`` by default
  717. (Issue #2737).
  718. - Apps can now define how tasks are named (:meth:`@gen_task_name`).
  719. Contributed by Dmitry Malinovsky
  720. - Module ``celery.worker.job`` renamed to :mod:`celery.worker.request`.
  721. - Beat: ``Scheduler.Publisher``/``.publisher`` renamed to
  722. ``.Producer``/``.producer``.
  723. Incompatible changes
  724. ====================
  725. - Prefork: Calling ``result.get()`` or joining any result from within a task
  726. now raises :exc:`RuntimeError`.
  727. In previous versions this would emit a warning.
  728. - :mod:`celery.worker.consumer` is now a package, not a module.
  729. - Result: The task_name argument/attribute of :class:`@AsyncResult` was
  730. removed.
  731. This was historically a field used for :mod:`pickle` compatibility,
  732. but is no longer needed.
  733. - Backends: Arguments named ``status`` renamed to ``state``.
  734. - Backends: ``backend.get_status()`` renamed to ``backend.get_state()``.
  735. Unscheduled Removals
  736. ====================
  737. - The experimental :mod:`celery.contrib.methods` feature has been removed,
  738. as there were far many bugs in the implementation to be useful.
  739. - The CentOS init scripts have been removed.
  740. These did not really add any features over the generic init scripts,
  741. so you are encouraged to use them instead, or something like
  742. ``supervisord``.
  743. .. _v400-removals:
  744. Scheduled Removals
  745. ==================
  746. Modules
  747. -------
  748. - Module ``celery.worker.job`` has been renamed to :mod:`celery.worker.request`.
  749. This was an internal module so should not have any effect.
  750. It is now part of the public API so should not change again.
  751. - Module ``celery.task.trace`` has been renamed to ``celery.app.trace``
  752. as the ``celery.task`` package is being phased out. The compat module
  753. will be removed in version 4.0 so please change any import from::
  754. from celery.task.trace import X
  755. to::
  756. from celery.app.trace import X
  757. - Old compatibility aliases in the :mod:`celery.loaders` module
  758. has been removed.
  759. - Removed ``celery.loaders.current_loader()``, use: ``current_app.loader``
  760. - Removed ``celery.loaders.load_settings()``, use: ``current_app.conf``
  761. Result
  762. ------
  763. - ``AsyncResult.serializable()`` and ``celery.result.from_serializable``
  764. has been removed:
  765. Use instead:
  766. .. code-block:: pycon
  767. >>> tup = result.as_tuple()
  768. >>> from celery.result import result_from_tuple
  769. >>> result = result_from_tuple(tup)
  770. - Removed ``BaseAsyncResult``, use ``AsyncResult`` for instance checks
  771. instead.
  772. - Removed ``TaskSetResult``, use ``GroupResult`` instead.
  773. - ``TaskSetResult.total`` -> ``len(GroupResult)``
  774. - ``TaskSetResult.taskset_id`` -> ``GroupResult.id``
  775. - Removed ``ResultSet.subtasks``, use ``ResultSet.results`` instead.
  776. TaskSet
  777. -------
  778. TaskSet has been renamed to group and TaskSet will be removed in version 4.0.
  779. Old::
  780. >>> from celery.task import TaskSet
  781. >>> TaskSet(add.subtask((i, i)) for i in xrange(10)).apply_async()
  782. New::
  783. >>> from celery import group
  784. >>> group(add.s(i, i) for i in xrange(10))()
  785. Events
  786. ------
  787. - Removals for class :class:`celery.events.state.Worker`:
  788. - ``Worker._defaults`` attribute.
  789. Use ``{k: getattr(worker, k) for k in worker._fields}``.
  790. - ``Worker.update_heartbeat``
  791. Use ``Worker.event(None, timestamp, received)``
  792. - ``Worker.on_online``
  793. Use ``Worker.event('online', timestamp, received, fields)``
  794. - ``Worker.on_offline``
  795. Use ``Worker.event('offline', timestamp, received, fields)``
  796. - ``Worker.on_heartbeat``
  797. Use ``Worker.event('heartbeat', timestamp, received, fields)``
  798. - Removals for class :class:`celery.events.state.Task`:
  799. - ``Task._defaults`` attribute.
  800. Use ``{k: getattr(task, k) for k in task._fields}``.
  801. - ``Task.on_sent``
  802. Use ``Worker.event('sent', timestamp, received, fields)``
  803. - ``Task.on_received``
  804. Use ``Task.event('received', timestamp, received, fields)``
  805. - ``Task.on_started``
  806. Use ``Task.event('started', timestamp, received, fields)``
  807. - ``Task.on_failed``
  808. Use ``Task.event('failed', timestamp, received, fields)``
  809. - ``Task.on_retried``
  810. Use ``Task.event('retried', timestamp, received, fields)``
  811. - ``Task.on_succeeded``
  812. Use ``Task.event('succeeded', timestamp, received, fields)``
  813. - ``Task.on_revoked``
  814. Use ``Task.event('revoked', timestamp, received, fields)``
  815. - ``Task.on_unknown_event``
  816. Use ``Task.event(short_type, timestamp, received, fields)``
  817. - ``Task.update``
  818. Use ``Task.event(short_type, timestamp, received, fields)``
  819. - ``Task.merge``
  820. Contact us if you need this.
  821. Magic keyword arguments
  822. -----------------------
  823. Support for the very old magic keyword arguments accepted by tasks has finally
  824. been in 4.0.
  825. If you are still using these you have to rewrite any task still
  826. using the old ``celery.decorators`` module and depending
  827. on keyword arguments being passed to the task,
  828. for example::
  829. from celery.decorators import task
  830. @task()
  831. def add(x, y, task_id=None):
  832. print('My task id is %r' % (task_id,))
  833. should be rewritten into::
  834. from celery import task
  835. @task(bind=True)
  836. def add(self, x, y):
  837. print('My task id is {0.request.id}'.format(self))
  838. Settings
  839. --------
  840. The following settings have been removed, and is no longer supported:
  841. Logging Settings
  842. ~~~~~~~~~~~~~~~~
  843. ===================================== =====================================
  844. **Setting name** **Replace with**
  845. ===================================== =====================================
  846. ``CELERYD_LOG_LEVEL`` :option:`celery worker --loglevel`
  847. ``CELERYD_LOG_FILE`` :option:`celery worker --logfile`
  848. ``CELERYBEAT_LOG_LEVEL`` :option:`celery beat --loglevel`
  849. ``CELERYBEAT_LOG_FILE`` :option:`celery beat --loglevel`
  850. ``CELERYMON_LOG_LEVEL`` celerymon is deprecated, use flower.
  851. ``CELERYMON_LOG_FILE`` celerymon is deprecated, use flower.
  852. ``CELERYMON_LOG_FORMAT`` celerymon is deprecated, use flower.
  853. ===================================== =====================================
  854. Task Settings
  855. ~~~~~~~~~~~~~~
  856. ===================================== =====================================
  857. **Setting name** **Replace with**
  858. ===================================== =====================================
  859. ``CELERY_CHORD_PROPAGATES`` N/a
  860. ===================================== =====================================
  861. .. _v400-deprecations:
  862. Deprecations
  863. ============
  864. See the :ref:`deprecation-timeline`.
  865. .. _v400-fixes:
  866. Fixes
  867. =====