| 1 |
.. _whatsnew-2.5: |
| 2 |
|
| 3 |
========================== |
| 4 |
What's new in Celery 2.5 |
| 5 |
========================== |
| 6 |
|
| 7 |
Celery aims to be a flexible and reliable, best-of-breed solution |
| 8 |
to process vast amounts of messages in a distributed fashion, while |
| 9 |
providing operations with the tools to maintain such a system. |
| 10 |
|
| 11 |
Celery has a large and diverse community of users and contributors, |
| 12 |
you should come join us :ref:`on IRC <irc-channel>` |
| 13 |
or :ref:`our mailing-list <mailing-list>`. |
| 14 |
|
| 15 |
To read more about Celery you should visit our `website`_. |
| 16 |
|
| 17 |
While this version is backward compatible with previous versions |
| 18 |
it's important that you read the following section. |
| 19 |
|
| 20 |
If you use Celery in combination with Django you must also |
| 21 |
read the `django-celery changelog <djcelery:version-2.5.0>` and upgrade |
| 22 |
to :pypi:`django-celery 2.5 <django-celery>`. |
| 23 |
|
| 24 |
This version is officially supported on CPython 2.5, 2.6, 2.7, 3.2 and 3.3, |
| 25 |
as well as PyPy and Jython. |
| 26 |
|
| 27 |
|
| 28 |
.. _`website`: http://celeryproject.org/ |
| 29 |
|
| 30 |
.. contents:: |
| 31 |
:local: |
| 32 |
|
| 33 |
.. _v250-important: |
| 34 |
|
| 35 |
Important Notes |
| 36 |
=============== |
| 37 |
|
| 38 |
Broker connection pool now enabled by default |
| 39 |
--------------------------------------------- |
| 40 |
|
| 41 |
The default limit is 10 connections, if you have many threads/green-threads |
| 42 |
using connections at the same time you may want to tweak this limit |
| 43 |
to avoid contention. |
| 44 |
|
| 45 |
See the :setting:`BROKER_POOL_LIMIT` setting for more information. |
| 46 |
|
| 47 |
Also note that publishing tasks will be retried by default, to change |
| 48 |
this default or the default retry policy see |
| 49 |
:setting:`CELERY_TASK_PUBLISH_RETRY` and |
| 50 |
:setting:`CELERY_TASK_PUBLISH_RETRY_POLICY`. |
| 51 |
|
| 52 |
Rabbit Result Backend: Exchange is no longer *auto delete* |
| 53 |
---------------------------------------------------------- |
| 54 |
|
| 55 |
The exchange used for results in the Rabbit (AMQP) result backend |
| 56 |
used to have the *auto_delete* flag set, which could result in a |
| 57 |
race condition leading to an annoying warning. |
| 58 |
|
| 59 |
.. admonition:: For RabbitMQ users |
| 60 |
|
| 61 |
Old exchanges created with the *auto_delete* flag enabled has |
| 62 |
to be removed. |
| 63 |
|
| 64 |
The :program:`camqadm` command can be used to delete the |
| 65 |
previous exchange: |
| 66 |
|
| 67 |
.. code-block:: console |
| 68 |
|
| 69 |
$ camqadm exchange.delete celeryresults |
| 70 |
|
| 71 |
As an alternative to deleting the old exchange you can |
| 72 |
configure a new name for the exchange:: |
| 73 |
|
| 74 |
CELERY_RESULT_EXCHANGE = 'celeryresults2' |
| 75 |
|
| 76 |
But you have to make sure that all clients and workers |
| 77 |
use this new setting, so they're updated to use the same |
| 78 |
exchange name. |
| 79 |
|
| 80 |
Solution for hanging workers (but must be manually enabled) |
| 81 |
----------------------------------------------------------- |
| 82 |
|
| 83 |
The `CELERYD_FORCE_EXECV` setting has been added to solve |
| 84 |
a problem with deadlocks that originate when threads and fork is mixed |
| 85 |
together: |
| 86 |
|
| 87 |
.. code-block:: python |
| 88 |
|
| 89 |
CELERYD_FORCE_EXECV = True |
| 90 |
|
| 91 |
This setting is recommended for all users using the prefork pool, |
| 92 |
but especially users also using time limits or a max tasks per child |
| 93 |
setting. |
| 94 |
|
| 95 |
- See `Python Issue 6721`_ to read more about this issue, and why |
| 96 |
resorting to :func:`~os.execv`` is the only safe solution. |
| 97 |
|
| 98 |
Enabling this option will result in a slight performance penalty |
| 99 |
when new child worker processes are started, and it will also increase |
| 100 |
memory usage (but many platforms are optimized, so the impact may be |
| 101 |
minimal). Considering that it ensures reliability when replacing |
| 102 |
lost worker processes, it should be worth it. |
| 103 |
|
| 104 |
- It's already the default behavior on Windows. |
| 105 |
- It will be the default behavior for all platforms in a future version. |
| 106 |
|
| 107 |
.. _`Python Issue 6721`: http://bugs.python.org/issue6721#msg140215 |
| 108 |
|
| 109 |
.. _v250-optimizations: |
| 110 |
|
| 111 |
Optimization |
| 112 |
============ |
| 113 |
|
| 114 |
- The code path used when the worker executes a task has been heavily |
| 115 |
optimized, meaning the worker is able to process a great deal |
| 116 |
more tasks/second compared to previous versions. As an example the solo |
| 117 |
pool can now process up to 15000 tasks/second on a 4 core MacBook Pro |
| 118 |
when using the :pypi:`pylibrabbitmq` transport, where it previously |
| 119 |
could only do 5000 tasks/second. |
| 120 |
|
| 121 |
- The task error tracebacks are now much shorter. |
| 122 |
|
| 123 |
- Fixed a noticeable delay in task processing when rate limits are enabled. |
| 124 |
|
| 125 |
.. _v250-deprecations: |
| 126 |
|
| 127 |
Deprecation Time-line Changes |
| 128 |
============================= |
| 129 |
|
| 130 |
Removals |
| 131 |
-------- |
| 132 |
|
| 133 |
* The old :class:`TaskSet` signature of ``(task_name, list_of_tasks)`` |
| 134 |
can no longer be used (originally scheduled for removal in 2.4). |
| 135 |
The deprecated ``.task_name`` and ``.task`` attributes has also been |
| 136 |
removed. |
| 137 |
|
| 138 |
* The functions ``celery.execute.delay_task``, ``celery.execute.apply``, |
| 139 |
and ``celery.execute.apply_async`` has been removed (originally) |
| 140 |
scheduled for removal in 2.3). |
| 141 |
|
| 142 |
* The built-in ``ping`` task has been removed (originally scheduled |
| 143 |
for removal in 2.3). Please use the ping broadcast command |
| 144 |
instead. |
| 145 |
|
| 146 |
* It's no longer possible to import ``subtask`` and ``TaskSet`` |
| 147 |
from :mod:`celery.task.base`, please import them from :mod:`celery.task` |
| 148 |
instead (originally scheduled for removal in 2.4). |
| 149 |
|
| 150 |
Deprecated modules |
| 151 |
------------------ |
| 152 |
|
| 153 |
* The :mod:`celery.decorators` module has changed status |
| 154 |
from pending deprecation to deprecated, and is scheduled for removal |
| 155 |
in version 4.0. The ``celery.task`` module must be used instead. |
| 156 |
|
| 157 |
.. _v250-news: |
| 158 |
|
| 159 |
News |
| 160 |
==== |
| 161 |
|
| 162 |
Timezone support |
| 163 |
---------------- |
| 164 |
|
| 165 |
Celery can now be configured to treat all incoming and outgoing dates |
| 166 |
as UTC, and the local timezone can be configured. |
| 167 |
|
| 168 |
This isn't yet enabled by default, since enabling |
| 169 |
time zone support means workers running versions pre-2.5 |
| 170 |
will be out of sync with upgraded workers. |
| 171 |
|
| 172 |
To enable UTC you have to set :setting:`CELERY_ENABLE_UTC`:: |
| 173 |
|
| 174 |
CELERY_ENABLE_UTC = True |
| 175 |
|
| 176 |
When UTC is enabled, dates and times in task messages will be |
| 177 |
converted to UTC, and then converted back to the local timezone |
| 178 |
when received by a worker. |
| 179 |
|
| 180 |
You can change the local timezone using the :setting:`CELERY_TIMEZONE` |
| 181 |
setting. Installing the :pypi:`pytz` library is recommended when |
| 182 |
using a custom timezone, to keep timezone definition up-to-date, |
| 183 |
but it will fallback to a system definition of the timezone if available. |
| 184 |
|
| 185 |
UTC will enabled by default in version 3.0. |
| 186 |
|
| 187 |
.. note:: |
| 188 |
|
| 189 |
:pypi:`django-celery` will use the local timezone as specified by the |
| 190 |
``TIME_ZONE`` setting, it will also honor the new `USE_TZ`_ setting |
| 191 |
introduced in Django 1.4. |
| 192 |
|
| 193 |
.. _`USE_TZ`: https://docs.djangoproject.com/en/dev/topics/i18n/timezones/ |
| 194 |
|
| 195 |
New security serializer using cryptographic signing |
| 196 |
--------------------------------------------------- |
| 197 |
|
| 198 |
A new serializer has been added that signs and verifies the signature |
| 199 |
of messages. |
| 200 |
|
| 201 |
The name of the new serializer is ``auth``, and needs additional |
| 202 |
configuration to work (see :ref:`conf-security`). |
| 203 |
|
| 204 |
.. seealso:: |
| 205 |
|
| 206 |
:ref:`guide-security` |
| 207 |
|
| 208 |
Contributed by Mher Movsisyan. |
| 209 |
|
| 210 |
New :setting:`CELERY_ANNOTATIONS` setting |
| 211 |
----------------------------------------- |
| 212 |
|
| 213 |
This new setting enables the configuration to modify task classes |
| 214 |
and their attributes. |
| 215 |
|
| 216 |
The setting can be a dict, or a list of annotation objects that filter |
| 217 |
for tasks and return a map of attributes to change. |
| 218 |
|
| 219 |
As an example, this is an annotation to change the ``rate_limit`` attribute |
| 220 |
for the ``tasks.add`` task: |
| 221 |
|
| 222 |
.. code-block:: python |
| 223 |
|
| 224 |
CELERY_ANNOTATIONS = {'tasks.add': {'rate_limit': '10/s'}} |
| 225 |
|
| 226 |
or change the same for all tasks: |
| 227 |
|
| 228 |
.. code-block:: python |
| 229 |
|
| 230 |
CELERY_ANNOTATIONS = {'*': {'rate_limit': '10/s'}} |
| 231 |
|
| 232 |
You can change methods too, for example the ``on_failure`` handler: |
| 233 |
|
| 234 |
.. code-block:: python |
| 235 |
|
| 236 |
def my_on_failure(self, exc, task_id, args, kwargs, einfo): |
| 237 |
print('Oh no! Task failed: %r' % (exc,)) |
| 238 |
|
| 239 |
CELERY_ANNOTATIONS = {'*': {'on_failure': my_on_failure}} |
| 240 |
|
| 241 |
If you need more flexibility then you can also create objects |
| 242 |
that filter for tasks to annotate: |
| 243 |
|
| 244 |
.. code-block:: python |
| 245 |
|
| 246 |
class MyAnnotate(object): |
| 247 |
|
| 248 |
def annotate(self, task): |
| 249 |
if task.name.startswith('tasks.'): |
| 250 |
return {'rate_limit': '10/s'} |
| 251 |
|
| 252 |
CELERY_ANNOTATIONS = (MyAnnotate(), {other_annotations,}) |
| 253 |
|
| 254 |
``current`` provides the currently executing task |
| 255 |
------------------------------------------------- |
| 256 |
|
| 257 |
The new :data:`celery.task.current` proxy will always give the currently |
| 258 |
executing task. |
| 259 |
|
| 260 |
**Example**: |
| 261 |
|
| 262 |
.. code-block:: python |
| 263 |
|
| 264 |
from celery.task import current, task |
| 265 |
|
| 266 |
@task |
| 267 |
def update_twitter_status(auth, message): |
| 268 |
twitter = Twitter(auth) |
| 269 |
try: |
| 270 |
twitter.update_status(message) |
| 271 |
except twitter.FailWhale, exc: |
| 272 |
# retry in 10 seconds. |
| 273 |
current.retry(countdown=10, exc=exc) |
| 274 |
|
| 275 |
Previously you'd've to type ``update_twitter_status.retry(…)`` |
| 276 |
here, which can be annoying for long task names. |
| 277 |
|
| 278 |
.. note:: |
| 279 |
This won't work if the task function is called directly (i.e., |
| 280 |
``update_twitter_status(a, b)``). For that to work ``apply`` must |
| 281 |
be used: ``update_twitter_status.apply((a, b))``. |
| 282 |
|
| 283 |
In Other News |
| 284 |
------------- |
| 285 |
|
| 286 |
- Now depends on Kombu 2.1.0. |
| 287 |
|
| 288 |
- Efficient Chord support for the Memcached backend (Issue #533) |
| 289 |
|
| 290 |
This means Memcached joins Redis in the ability to do non-polling |
| 291 |
chords. |
| 292 |
|
| 293 |
Contributed by Dan McGee. |
| 294 |
|
| 295 |
- Adds Chord support for the Rabbit result backend (amqp) |
| 296 |
|
| 297 |
The Rabbit result backend can now use the fallback chord solution. |
| 298 |
|
| 299 |
- Sending :sig:`QUIT` to ``celeryd`` will now cause it cold terminate. |
| 300 |
|
| 301 |
That is, it won't finish executing the tasks it's currently |
| 302 |
working on. |
| 303 |
|
| 304 |
Contributed by Alec Clowes. |
| 305 |
|
| 306 |
- New "detailed" mode for the Cassandra backend. |
| 307 |
|
| 308 |
Allows to have a "detailed" mode for the Cassandra backend. |
| 309 |
Basically the idea is to keep all states using Cassandra wide columns. |
| 310 |
New states are then appended to the row as new columns, the last state |
| 311 |
being the last column. |
| 312 |
|
| 313 |
See the :setting:`CASSANDRA_DETAILED_MODE` setting. |
| 314 |
|
| 315 |
Contributed by Steeve Morin. |
| 316 |
|
| 317 |
- The Crontab parser now matches Vixie Cron behavior when parsing ranges |
| 318 |
with steps (e.g., 1-59/2). |
| 319 |
|
| 320 |
Contributed by Daniel Hepper. |
| 321 |
|
| 322 |
- ``celerybeat`` can now be configured on the command-line like ``celeryd``. |
| 323 |
|
| 324 |
Additional configuration must be added at the end of the argument list |
| 325 |
followed by ``--``, for example: |
| 326 |
|
| 327 |
.. code-block:: console |
| 328 |
|
| 329 |
$ celerybeat -l info -- celerybeat.max_loop_interval=10.0 |
| 330 |
|
| 331 |
- Now limits the number of frames in a traceback so that ``celeryd`` doesn't |
| 332 |
crash on maximum recursion limit exceeded exceptions (Issue #615). |
| 333 |
|
| 334 |
The limit is set to the current recursion limit divided by 8 (which |
| 335 |
is 125 by default). |
| 336 |
|
| 337 |
To get or set the current recursion limit use |
| 338 |
:func:`sys.getrecursionlimit` and :func:`sys.setrecursionlimit`. |
| 339 |
|
| 340 |
- More information is now preserved in the pickleable traceback. |
| 341 |
|
| 342 |
This has been added so that Sentry can show more details. |
| 343 |
|
| 344 |
Contributed by Sean O'Connor. |
| 345 |
|
| 346 |
- CentOS init-script has been updated and should be more flexible. |
| 347 |
|
| 348 |
Contributed by Andrew McFague. |
| 349 |
|
| 350 |
- MongoDB result backend now supports ``forget()``. |
| 351 |
|
| 352 |
Contributed by Andrew McFague |
| 353 |
|
| 354 |
- ``task.retry()`` now re-raises the original exception keeping |
| 355 |
the original stack trace. |
| 356 |
|
| 357 |
Suggested by :github_user:`ojii`. |
| 358 |
|
| 359 |
- The `--uid` argument to daemons now uses ``initgroups()`` to set |
| 360 |
groups to all the groups the user is a member of. |
| 361 |
|
| 362 |
Contributed by Łukasz Oleś. |
| 363 |
|
| 364 |
- ``celeryctl``: Added ``shell`` command. |
| 365 |
|
| 366 |
The shell will have the current_app (``celery``) and all tasks |
| 367 |
automatically added to locals. |
| 368 |
|
| 369 |
- ``celeryctl``: Added ``migrate`` command. |
| 370 |
|
| 371 |
The migrate command moves all tasks from one broker to another. |
| 372 |
Note that this is experimental and you should have a backup |
| 373 |
of the data before proceeding. |
| 374 |
|
| 375 |
**Examples**: |
| 376 |
|
| 377 |
.. code-block:: console |
| 378 |
|
| 379 |
$ celeryctl migrate redis://localhost amqp://localhost |
| 380 |
$ celeryctl migrate amqp://localhost//v1 amqp://localhost//v2 |
| 381 |
$ python manage.py celeryctl migrate django:// redis:// |
| 382 |
|
| 383 |
* Routers can now override the ``exchange`` and ``routing_key`` used |
| 384 |
to create missing queues (Issue #577). |
| 385 |
|
| 386 |
By default this will always use the name of the queue, |
| 387 |
but you can now have a router return exchange and routing_key keys |
| 388 |
to set them. |
| 389 |
|
| 390 |
This is useful when using routing classes which decides a destination |
| 391 |
at run-time. |
| 392 |
|
| 393 |
Contributed by Akira Matsuzaki. |
| 394 |
|
| 395 |
- Redis result backend: Adds support for a ``max_connections`` parameter. |
| 396 |
|
| 397 |
It's now possible to configure the maximum number of |
| 398 |
simultaneous connections in the Redis connection pool used for |
| 399 |
results. |
| 400 |
|
| 401 |
The default max connections setting can be configured using the |
| 402 |
:setting:`CELERY_REDIS_MAX_CONNECTIONS` setting, |
| 403 |
or it can be changed individually by ``RedisBackend(max_connections=int)``. |
| 404 |
|
| 405 |
Contributed by Steeve Morin. |
| 406 |
|
| 407 |
- Redis result backend: Adds the ability to wait for results without polling. |
| 408 |
|
| 409 |
Contributed by Steeve Morin. |
| 410 |
|
| 411 |
- MongoDB result backend: Now supports save and restore ``taskset``. |
| 412 |
|
| 413 |
Contributed by Julien Poissonnier. |
| 414 |
|
| 415 |
- There's a new :ref:`guide-security` guide in the documentation. |
| 416 |
|
| 417 |
- The init-scripts have been updated, and many bugs fixed. |
| 418 |
|
| 419 |
Contributed by Chris Streeter. |
| 420 |
|
| 421 |
- User (tilde) is now expanded in command-line arguments. |
| 422 |
|
| 423 |
- Can now configure :envvar:`CELERYCTL` environment variable |
| 424 |
in :file:`/etc/default/celeryd`. |
| 425 |
|
| 426 |
While not necessary for operation, :program:`celeryctl` is used for the |
| 427 |
``celeryd status`` command, and the path to :program:`celeryctl` must be |
| 428 |
configured for that to work. |
| 429 |
|
| 430 |
The daemonization cookbook contains examples. |
| 431 |
|
| 432 |
Contributed by Jude Nagurney. |
| 433 |
|
| 434 |
- The MongoDB result backend can now use Replica Sets. |
| 435 |
|
| 436 |
Contributed by Ivan Metzlar. |
| 437 |
|
| 438 |
- gevent: Now supports autoscaling (Issue #599). |
| 439 |
|
| 440 |
Contributed by Mark Lavin. |
| 441 |
|
| 442 |
- multiprocessing: Mediator thread is now always enabled, |
| 443 |
even though rate limits are disabled, as the pool semaphore |
| 444 |
is known to block the main thread, causing broadcast commands and |
| 445 |
shutdown to depend on the semaphore being released. |
| 446 |
|
| 447 |
Fixes |
| 448 |
===== |
| 449 |
|
| 450 |
- Exceptions that are re-raised with a new exception object now keeps |
| 451 |
the original stack trace. |
| 452 |
|
| 453 |
- Windows: Fixed the ``no handlers found for multiprocessing`` warning. |
| 454 |
|
| 455 |
- Windows: The ``celeryd`` program can now be used. |
| 456 |
|
| 457 |
Previously Windows users had to launch ``celeryd`` using |
| 458 |
``python -m celery.bin.celeryd``. |
| 459 |
|
| 460 |
- Redis result backend: Now uses ``SETEX`` command to set result key, |
| 461 |
and expiry atomically. |
| 462 |
|
| 463 |
Suggested by :github_user:`yaniv-aknin`. |
| 464 |
|
| 465 |
- ``celeryd``: Fixed a problem where shutdown hanged when :kbd:`Control-c` |
| 466 |
was used to terminate. |
| 467 |
|
| 468 |
- ``celeryd``: No longer crashes when channel errors occur. |
| 469 |
|
| 470 |
Fix contributed by Roger Hu. |
| 471 |
|
| 472 |
- Fixed memory leak in the eventlet pool, caused by the |
| 473 |
use of ``greenlet.getcurrent``. |
| 474 |
|
| 475 |
Fix contributed by Ignas Mikalajūnas. |
| 476 |
|
| 477 |
|
| 478 |
- Cassandra backend: No longer uses :func:`pycassa.connect` which is |
| 479 |
deprecated since :pypi:`pycassa` 1.4. |
| 480 |
|
| 481 |
Fix contributed by Jeff Terrace. |
| 482 |
|
| 483 |
- Fixed unicode decode errors that could occur while sending error emails. |
| 484 |
|
| 485 |
Fix contributed by Seong Wun Mun. |
| 486 |
|
| 487 |
- ``celery.bin`` programs now always defines ``__package__`` as recommended |
| 488 |
by PEP-366. |
| 489 |
|
| 490 |
- ``send_task`` now emits a warning when used in combination with |
| 491 |
:setting:`CELERY_ALWAYS_EAGER` (Issue #581). |
| 492 |
|
| 493 |
Contributed by Mher Movsisyan. |
| 494 |
|
| 495 |
- ``apply_async`` now forwards the original keyword arguments to ``apply`` |
| 496 |
when :setting:`CELERY_ALWAYS_EAGER` is enabled. |
| 497 |
|
| 498 |
- ``celeryev`` now tries to re-establish the connection if the connection |
| 499 |
to the broker is lost (Issue #574). |
| 500 |
|
| 501 |
- ``celeryev``: Fixed a crash occurring if a task has no associated worker |
| 502 |
information. |
| 503 |
|
| 504 |
Fix contributed by Matt Williamson. |
| 505 |
|
| 506 |
- The current date and time is now consistently taken from the current loaders |
| 507 |
``now`` method. |
| 508 |
|
| 509 |
- Now shows helpful error message when given a configuration module ending in |
| 510 |
``.py`` that can't be imported. |
| 511 |
|
| 512 |
- ``celeryctl``: The :option:`--expires <celery call --expires>` and |
| 513 |
:option:`--eta <celery call --eta>` arguments to the apply command |
| 514 |
can now be an ISO-8601 formatted string. |
| 515 |
|
| 516 |
- ``celeryctl`` now exits with exit status ``EX_UNAVAILABLE`` (69) if no replies |
| 517 |
have been received. |