Skip to content

Commit 2e86924

Browse files
committed
AMQP Backend: Now expires results by default.
The CELERY_AMQP_TASK_RESULT_EXPIRES setting has been deprecated and will be removed in version 3.0. Instead the amqp backend now uses the CELERY_TASK_RESULT_EXPIRES setting as used by all the other backends. Queue leases are only supported by RabbitMQ versions 1.1.0 and higher, so if you are running an older version you need to disable expiration by setting:: CELERY_TASK_RESULT_EXPIRES = None
1 parent f6a5c31 commit 2e86924

File tree

4 files changed

+124
-83
lines changed

4 files changed

+124
-83
lines changed

Changelog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ Important Notes
1717

1818
* Now depends on Kombu 1.3.0
1919

20+
* AMQP Result backend: Now expires results by default.
21+
22+
The default expiration value is now taken from the
23+
:setting:`CELERY_TASK_RESULT_EXPIRES` setting.
24+
25+
The old :setting:`CELERY_AMQP_TASK_RESULT_EXPIRES` setting has been
26+
deprecated and will be removed in version 3.0.
27+
28+
Note that this means that the result backend requires RabbitMQ 1.1.0 or
29+
higher, and that you have to disable expiration if you are running
30+
with an older version. You can do so by disabling the
31+
:setting:`CELERY_TASK_RESULT_EXPIRES` setting::
32+
33+
CELERY_TASK_RESULT_EXPIRES = None
34+
2035
* The deprecated :func:`celery.loaders.setup_loader` function has been removed.
2136

2237
* Deprecations

celery/backends/amqp.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AMQPBackend(BaseDictBackend):
3939

4040
def __init__(self, connection=None, exchange=None, exchange_type=None,
4141
persistent=None, serializer=None, auto_delete=True,
42-
expires=None, **kwargs):
42+
**kwargs):
4343
super(AMQPBackend, self).__init__(**kwargs)
4444
conf = self.app.conf
4545
self._connection = connection
@@ -56,11 +56,19 @@ def __init__(self, connection=None, exchange=None, exchange_type=None,
5656
auto_delete=auto_delete)
5757
self.serializer = serializer or conf.CELERY_RESULT_SERIALIZER
5858
self.auto_delete = auto_delete
59-
self.expires = (conf.CELERY_AMQP_TASK_RESULT_EXPIRES if expires is None
60-
else expires)
61-
if self.expires is not None:
62-
self.expires = self.prepare_expires(self.expires)
63-
# x-expires requires RabbitMQ 2.1.0 or higher.
59+
60+
# AMQP_TASK_RESULT_EXPIRES setting is deprecated and will be
61+
# removed in version 3.0.
62+
dexpires = conf.CELERY_AMQP_TASK_RESULT_EXPIRES
63+
64+
self.expires = None
65+
if "expires" in kwargs:
66+
if kwargs["expires"] is not None:
67+
self.expires = self.prepare_expires(kwargs["expires"])
68+
else:
69+
self.expires = self.prepare_expires(dexpires)
70+
71+
if self.expires:
6472
self.queue_arguments["x-expires"] = int(self.expires * 1000)
6573
self.mutex = threading.Lock()
6674

celery/tests/test_backends/test_amqp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def test_repair_uuid(self):
7474
tid = uuid()
7575
self.assertEqual(repair_uuid(tid.replace("-", "")), tid)
7676

77-
def test_expires_defaults_to_config(self):
77+
def test_expires_defaults_to_config_deprecated_setting(self):
7878
app = app_or_default()
7979
prev = app.conf.CELERY_AMQP_TASK_RESULT_EXPIRES
8080
app.conf.CELERY_AMQP_TASK_RESULT_EXPIRES = 10
8181
try:
82-
b = self.create_backend(expires=None)
82+
b = self.create_backend()
8383
self.assertEqual(b.queue_arguments.get("x-expires"), 10 * 1000.0)
8484
finally:
8585
app.conf.CELERY_AMQP_TASK_RESULT_EXPIRES = prev

docs/configuration.rst

Lines changed: 93 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,13 @@ Example configuration
202202
AMQP backend settings
203203
---------------------
204204

205-
.. setting:: CELERY_AMQP_TASK_RESULT_EXPIRES
206-
207-
CELERY_AMQP_TASK_RESULT_EXPIRES
208-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209-
.. deprecated:: 2.5
210-
211-
The time in seconds of which the task result queues should expire.
212-
213-
This setting is deprecated, and will be removed in version 3.0.
214-
Please use :setting:`CELERY_TASK_RESULT_EXPIRES` instead.
215-
216205
.. note::
217206

218-
AMQP result expiration requires RabbitMQ versions 2.1.0 and higher.
207+
The AMQP backend requires RabbitMQ 1.1.0 or higher to automatically
208+
expire results. If you are running an older version of RabbitmQ
209+
you should disable result expiration like this:
210+
211+
CELERY_TASK_RESULT_EXPIRES = None
219212

220213
.. setting:: CELERY_RESULT_EXCHANGE
221214

@@ -728,7 +721,6 @@ A built-in periodic task will delete the results after this time
728721
When using the database or MongoDB backends, `celerybeat` must be
729722
running for the results to be expired.
730723

731-
732724
.. setting:: CELERY_MAX_CACHED_RESULTS
733725

734726
CELERY_MAX_CACHED_RESULTS
@@ -959,18 +951,6 @@ The default value for the `Task.send_error_emails` attribute, which if
959951
set to :const:`True` means errors occurring during task execution will be
960952
sent to :setting:`ADMINS` by email.
961953

962-
.. setting:: CELERY_TASK_ERROR_WHITELIST
963-
964-
CELERY_TASK_ERROR_WHITELIST
965-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
966-
967-
.. deprecated:: 2.5
968-
969-
A white list of exceptions to send error emails for.
970-
971-
This option is pending deprecation and is scheduled for removal
972-
in version 3.0.
973-
974954
.. setting:: ADMINS
975955

976956
ADMINS
@@ -1155,39 +1135,6 @@ this behavior.
11551135
Logging can also be customized by connecting to the
11561136
:signal:`celery.signals.setup_logging` signal.
11571137

1158-
.. setting:: CELERYD_LOG_FILE
1159-
1160-
CELERYD_LOG_FILE
1161-
~~~~~~~~~~~~~~~~
1162-
1163-
.. deprecated:: 2.4
1164-
1165-
This option is deprecated and is scheduled for removal in version 3.0.
1166-
Please use the :option:`--logfile` argument instead.
1167-
1168-
The default file name the worker daemon logs messages to. Can be overridden
1169-
using the :option:`--logfile` option to :mod:`~celery.bin.celeryd`.
1170-
1171-
The default is :const:`None` (`stderr`)
1172-
1173-
.. setting:: CELERYD_LOG_LEVEL
1174-
1175-
CELERYD_LOG_LEVEL
1176-
~~~~~~~~~~~~~~~~~
1177-
1178-
.. deprecated:: 2.4
1179-
1180-
This option is deprecated and is scheduled for removal in version 3.0.
1181-
Please use the :option:`--loglevel` argument instead.
1182-
1183-
Worker log level, can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
1184-
:const:`ERROR` or :const:`CRITICAL`.
1185-
1186-
Can also be set via the :option:`--loglevel` argument to
1187-
:mod:`~celery.bin.celeryd`.
1188-
1189-
See the :mod:`logging` module for more information.
1190-
11911138
.. setting:: CELERYD_LOG_COLOR
11921139

11931140
CELERYD_LOG_COLOR
@@ -1347,6 +1294,94 @@ CELERYBEAT_MAX_LOOP_INTERVAL
13471294
The maximum number of seconds :mod:`~celery.bin.celerybeat` can sleep
13481295
between checking the schedule. Default is 300 seconds (5 minutes).
13491296

1297+
1298+
.. _conf-celerymon:
1299+
1300+
Monitor Server: celerymon
1301+
-------------------------
1302+
1303+
1304+
.. setting:: CELERYMON_LOG_FORMAT
1305+
1306+
CELERYMON_LOG_FORMAT
1307+
~~~~~~~~~~~~~~~~~~~~
1308+
1309+
The format to use for log messages.
1310+
1311+
Default is `[%(asctime)s: %(levelname)s/%(processName)s] %(message)s`
1312+
1313+
See the Python :mod:`logging` module for more information about log
1314+
formats.
1315+
1316+
.. _conf-deprecated:
1317+
1318+
Deprecated Settings
1319+
-------------------
1320+
1321+
These settings have been deprecated and should no longer used,
1322+
as they will be removed in future versions.
1323+
1324+
.. setting:: CELERY_AMQP_TASK_RESULT_EXPIRES
1325+
1326+
CELERY_AMQP_TASK_RESULT_EXPIRES
1327+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1328+
1329+
.. deprecated:: 2.5
1330+
1331+
The time in seconds of which the task result queues should expire.
1332+
1333+
This setting is deprecated, and will be removed in version 3.0.
1334+
Please use :setting:`CELERY_TASK_RESULT_EXPIRES` instead.
1335+
1336+
.. note::
1337+
1338+
AMQP result expiration requires RabbitMQ versions 2.1.0 and higher.
1339+
1340+
.. setting:: CELERY_TASK_ERROR_WHITELIST
1341+
1342+
CELERY_TASK_ERROR_WHITELIST
1343+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
1344+
1345+
.. deprecated:: 2.5
1346+
1347+
A white list of exceptions to send error emails for.
1348+
1349+
This option is pending deprecation and is scheduled for removal
1350+
in version 3.0.
1351+
1352+
.. setting:: CELERYD_LOG_FILE
1353+
1354+
CELERYD_LOG_FILE
1355+
~~~~~~~~~~~~~~~~
1356+
1357+
.. deprecated:: 2.4
1358+
1359+
This option is deprecated and is scheduled for removal in version 3.0.
1360+
Please use the :option:`--logfile` argument instead.
1361+
1362+
The default file name the worker daemon logs messages to. Can be overridden
1363+
using the :option:`--logfile` option to :mod:`~celery.bin.celeryd`.
1364+
1365+
The default is :const:`None` (`stderr`)
1366+
1367+
.. setting:: CELERYD_LOG_LEVEL
1368+
1369+
CELERYD_LOG_LEVEL
1370+
~~~~~~~~~~~~~~~~~
1371+
1372+
.. deprecated:: 2.4
1373+
1374+
This option is deprecated and is scheduled for removal in version 3.0.
1375+
Please use the :option:`--loglevel` argument instead.
1376+
1377+
Worker log level, can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
1378+
:const:`ERROR` or :const:`CRITICAL`.
1379+
1380+
Can also be set via the :option:`--loglevel` argument to
1381+
:mod:`~celery.bin.celeryd`.
1382+
1383+
See the :mod:`logging` module for more information.
1384+
13501385
.. setting:: CELERYBEAT_LOG_FILE
13511386

13521387
CELERYBEAT_LOG_FILE
@@ -1380,11 +1415,6 @@ Can also be set via the :option:`--loglevel` argument to
13801415

13811416
See the :mod:`logging` module for more information.
13821417

1383-
.. _conf-celerymon:
1384-
1385-
Monitor Server: celerymon
1386-
-------------------------
1387-
13881418
.. setting:: CELERYMON_LOG_FILE
13891419

13901420
CELERYMON_LOG_FILE
@@ -1414,15 +1444,3 @@ Logging level. Can be any of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`,
14141444
:const:`ERROR`, or :const:`CRITICAL`.
14151445

14161446
See the :mod:`logging` module for more information.
1417-
1418-
.. setting:: CELERYMON_LOG_FORMAT
1419-
1420-
CELERYMON_LOG_FORMAT
1421-
~~~~~~~~~~~~~~~~~~~~
1422-
1423-
The format to use for log messages.
1424-
1425-
Default is `[%(asctime)s: %(levelname)s/%(processName)s] %(message)s`
1426-
1427-
See the Python :mod:`logging` module for more information about log
1428-
formats.

0 commit comments

Comments
 (0)