whatsnew-4.0.rst 36 KB

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