| 1 |
.. _configuration: |
| 2 |
|
| 3 |
============================ |
| 4 |
Configuration and defaults |
| 5 |
============================ |
| 6 |
|
| 7 |
This document describes the configuration options available. |
| 8 |
|
| 9 |
If you're using the default loader, you must create the :file:`celeryconfig.py` |
| 10 |
module and make sure it's available on the Python path. |
| 11 |
|
| 12 |
.. contents:: |
| 13 |
:local: |
| 14 |
:depth: 2 |
| 15 |
|
| 16 |
.. _conf-example: |
| 17 |
|
| 18 |
Example configuration file |
| 19 |
========================== |
| 20 |
|
| 21 |
This is an example configuration file to get you started. |
| 22 |
It should contain all you need to run a basic Celery set-up. |
| 23 |
|
| 24 |
.. code-block:: python |
| 25 |
|
| 26 |
## Broker settings. |
| 27 |
broker_url = 'amqp://guest:guest@localhost:5672//' |
| 28 |
|
| 29 |
# List of modules to import when the Celery worker starts. |
| 30 |
imports = ('myapp.tasks',) |
| 31 |
|
| 32 |
## Using the database to store task state and results. |
| 33 |
result_backend = 'db+sqlite:///results.db' |
| 34 |
|
| 35 |
task_annotations = {'tasks.add': {'rate_limit': '10/s'}} |
| 36 |
|
| 37 |
|
| 38 |
.. _conf-old-settings-map: |
| 39 |
|
| 40 |
New lowercase settings |
| 41 |
====================== |
| 42 |
|
| 43 |
Version 4.0 introduced new lower case settings and setting organization. |
| 44 |
|
| 45 |
The major difference between previous versions, apart from the lower case |
| 46 |
names, are the renaming of some prefixes, like ``celery_beat_`` to ``beat_``, |
| 47 |
``celeryd_`` to ``worker_``, and most of the top level ``celery_`` settings |
| 48 |
have been moved into a new ``task_`` prefix. |
| 49 |
|
| 50 |
.. warning:: |
| 51 |
|
| 52 |
Celery will still be able to read old configuration files until Celery 6.0. |
| 53 |
Afterwards, support for the old configuration files will be removed. |
| 54 |
We provide the ``celery upgrade`` command that should handle |
| 55 |
plenty of cases (including :ref:`Django <latentcall-django-admonition>`). |
| 56 |
|
| 57 |
Please migrate to the new configuration scheme as soon as possible. |
| 58 |
|
| 59 |
|
| 60 |
========================================== ============================================== |
| 61 |
**Setting name** **Replace with** |
| 62 |
========================================== ============================================== |
| 63 |
``CELERY_ACCEPT_CONTENT`` :setting:`accept_content` |
| 64 |
``CELERY_ENABLE_UTC`` :setting:`enable_utc` |
| 65 |
``CELERY_IMPORTS`` :setting:`imports` |
| 66 |
``CELERY_INCLUDE`` :setting:`include` |
| 67 |
``CELERY_TIMEZONE`` :setting:`timezone` |
| 68 |
``CELERYBEAT_MAX_LOOP_INTERVAL`` :setting:`beat_max_loop_interval` |
| 69 |
``CELERYBEAT_SCHEDULE`` :setting:`beat_schedule` |
| 70 |
``CELERYBEAT_SCHEDULER`` :setting:`beat_scheduler` |
| 71 |
``CELERYBEAT_SCHEDULE_FILENAME`` :setting:`beat_schedule_filename` |
| 72 |
``CELERYBEAT_SYNC_EVERY`` :setting:`beat_sync_every` |
| 73 |
``BROKER_URL`` :setting:`broker_url` |
| 74 |
``BROKER_TRANSPORT`` :setting:`broker_transport` |
| 75 |
``BROKER_TRANSPORT_OPTIONS`` :setting:`broker_transport_options` |
| 76 |
``BROKER_CONNECTION_TIMEOUT`` :setting:`broker_connection_timeout` |
| 77 |
``BROKER_CONNECTION_RETRY`` :setting:`broker_connection_retry` |
| 78 |
``BROKER_CONNECTION_MAX_RETRIES`` :setting:`broker_connection_max_retries` |
| 79 |
``BROKER_FAILOVER_STRATEGY`` :setting:`broker_failover_strategy` |
| 80 |
``BROKER_HEARTBEAT`` :setting:`broker_heartbeat` |
| 81 |
``BROKER_LOGIN_METHOD`` :setting:`broker_login_method` |
| 82 |
``BROKER_NATIVE_DELAYED_DELIVERY_QUEUE_TYPE`` :setting:`broker_native_delayed_delivery_queue_type` |
| 83 |
``BROKER_POOL_LIMIT`` :setting:`broker_pool_limit` |
| 84 |
``BROKER_USE_SSL`` :setting:`broker_use_ssl` |
| 85 |
``CELERY_CACHE_BACKEND`` :setting:`cache_backend` |
| 86 |
``CELERY_CACHE_BACKEND_OPTIONS`` :setting:`cache_backend_options` |
| 87 |
``CASSANDRA_COLUMN_FAMILY`` :setting:`cassandra_table` |
| 88 |
``CASSANDRA_ENTRY_TTL`` :setting:`cassandra_entry_ttl` |
| 89 |
``CASSANDRA_KEYSPACE`` :setting:`cassandra_keyspace` |
| 90 |
``CASSANDRA_PORT`` :setting:`cassandra_port` |
| 91 |
``CASSANDRA_READ_CONSISTENCY`` :setting:`cassandra_read_consistency` |
| 92 |
``CASSANDRA_SERVERS`` :setting:`cassandra_servers` |
| 93 |
``CASSANDRA_WRITE_CONSISTENCY`` :setting:`cassandra_write_consistency` |
| 94 |
``CASSANDRA_OPTIONS`` :setting:`cassandra_options` |
| 95 |
``S3_ACCESS_KEY_ID`` :setting:`s3_access_key_id` |
| 96 |
``S3_SECRET_ACCESS_KEY`` :setting:`s3_secret_access_key` |
| 97 |
``S3_BUCKET`` :setting:`s3_bucket` |
| 98 |
``S3_BASE_PATH`` :setting:`s3_base_path` |
| 99 |
``S3_ENDPOINT_URL`` :setting:`s3_endpoint_url` |
| 100 |
``S3_REGION`` :setting:`s3_region` |
| 101 |
``CELERY_COUCHBASE_BACKEND_SETTINGS`` :setting:`couchbase_backend_settings` |
| 102 |
``CELERY_ARANGODB_BACKEND_SETTINGS`` :setting:`arangodb_backend_settings` |
| 103 |
``CELERY_MONGODB_BACKEND_SETTINGS`` :setting:`mongodb_backend_settings` |
| 104 |
``CELERY_EVENT_QUEUE_EXPIRES`` :setting:`event_queue_expires` |
| 105 |
``CELERY_EVENT_QUEUE_TTL`` :setting:`event_queue_ttl` |
| 106 |
``CELERY_EVENT_QUEUE_DURABLE`` :setting:`event_queue_durable` |
| 107 |
``CELERY_EVENT_QUEUE_EXCLUSIVE`` :setting:`event_queue_exclusive` |
| 108 |
``CELERY_EVENT_QUEUE_PREFIX`` :setting:`event_queue_prefix` |
| 109 |
``CELERY_EVENT_SERIALIZER`` :setting:`event_serializer` |
| 110 |
``CELERY_REDIS_DB`` :setting:`redis_db` |
| 111 |
``CELERY_REDIS_HOST`` :setting:`redis_host` |
| 112 |
``CELERY_REDIS_MAX_CONNECTIONS`` :setting:`redis_max_connections` |
| 113 |
``CELERY_REDIS_USERNAME`` :setting:`redis_username` |
| 114 |
``CELERY_REDIS_PASSWORD`` :setting:`redis_password` |
| 115 |
``CELERY_REDIS_PORT`` :setting:`redis_port` |
| 116 |
``CELERY_REDIS_BACKEND_USE_SSL`` :setting:`redis_backend_use_ssl` |
| 117 |
``CELERY_REDIS_BACKEND_CREDENTIAL_PROVIDER`` :setting:`redis_backend_credential_provider` |
| 118 |
``CELERY_RESULT_BACKEND`` :setting:`result_backend` |
| 119 |
``CELERY_MAX_CACHED_RESULTS`` :setting:`result_cache_max` |
| 120 |
``CELERY_MESSAGE_COMPRESSION`` :setting:`result_compression` |
| 121 |
``CELERY_RESULT_EXCHANGE`` :setting:`result_exchange` |
| 122 |
``CELERY_RESULT_EXCHANGE_TYPE`` :setting:`result_exchange_type` |
| 123 |
``CELERY_RESULT_EXPIRES`` :setting:`result_expires` |
| 124 |
``CELERY_RESULT_PERSISTENT`` :setting:`result_persistent` |
| 125 |
``CELERY_RESULT_SERIALIZER`` :setting:`result_serializer` |
| 126 |
``CELERY_RESULT_DBURI`` Use :setting:`result_backend` instead. |
| 127 |
``CELERY_RESULT_ENGINE_OPTIONS`` :setting:`database_engine_options` |
| 128 |
``[...]_DB_SHORT_LIVED_SESSIONS`` :setting:`database_short_lived_sessions` |
| 129 |
``CELERY_RESULT_DB_TABLE_NAMES`` :setting:`database_db_names` |
| 130 |
``CELERY_SECURITY_CERTIFICATE`` :setting:`security_certificate` |
| 131 |
``CELERY_SECURITY_CERT_STORE`` :setting:`security_cert_store` |
| 132 |
``CELERY_SECURITY_KEY`` :setting:`security_key` |
| 133 |
``CELERY_SECURITY_KEY_PASSWORD`` :setting:`security_key_password` |
| 134 |
``CELERY_ACKS_LATE`` :setting:`task_acks_late` |
| 135 |
``CELERY_ACKS_ON_FAILURE_OR_TIMEOUT`` :setting:`task_acks_on_failure_or_timeout` |
| 136 |
``CELERY_TASK_ALWAYS_EAGER`` :setting:`task_always_eager` |
| 137 |
``CELERY_ANNOTATIONS`` :setting:`task_annotations` |
| 138 |
``CELERY_COMPRESSION`` :setting:`task_compression` |
| 139 |
``CELERY_CREATE_MISSING_QUEUES`` :setting:`task_create_missing_queues` |
| 140 |
``CELERY_CREATE_MISSING_QUEUE_TYPE`` :setting:`task_create_missing_queue_type` |
| 141 |
``CELERY_CREATE_MISSING_QUEUE_EXCHANGE_TYPE`` :setting:`task_create_missing_queue_exchange_type` |
| 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_QUEUE_TYPE`` :setting:`task_default_queue_type` |
| 147 |
``CELERY_DEFAULT_RATE_LIMIT`` :setting:`task_default_rate_limit` |
| 148 |
``CELERY_DEFAULT_ROUTING_KEY`` :setting:`task_default_routing_key` |
| 149 |
``CELERY_EAGER_PROPAGATES`` :setting:`task_eager_propagates` |
| 150 |
``CELERY_IGNORE_RESULT`` :setting:`task_ignore_result` |
| 151 |
``CELERY_PUBLISH_RETRY`` :setting:`task_publish_retry` |
| 152 |
``CELERY_PUBLISH_RETRY_POLICY`` :setting:`task_publish_retry_policy` |
| 153 |
``CELERY_QUEUES`` :setting:`task_queues` |
| 154 |
``CELERY_ROUTES`` :setting:`task_routes` |
| 155 |
``CELERY_SEND_SENT_EVENT`` :setting:`task_send_sent_event` |
| 156 |
``CELERY_TASK_SERIALIZER`` :setting:`task_serializer` |
| 157 |
``CELERYD_SOFT_TIME_LIMIT`` :setting:`task_soft_time_limit` |
| 158 |
``CELERY_TASK_TRACK_STARTED`` :setting:`task_track_started` |
| 159 |
``CELERY_TASK_REJECT_ON_WORKER_LOST`` :setting:`task_reject_on_worker_lost` |
| 160 |
``CELERYD_TIME_LIMIT`` :setting:`task_time_limit` |
| 161 |
``CELERY_ALLOW_ERROR_CB_ON_CHORD_HEADER`` :setting:`task_allow_error_cb_on_chord_header` |
| 162 |
``CELERYD_AGENT`` :setting:`worker_agent` |
| 163 |
``CELERYD_AUTOSCALER`` :setting:`worker_autoscaler` |
| 164 |
``CELERYD_CONCURRENCY`` :setting:`worker_concurrency` |
| 165 |
``CELERYD_CONSUMER`` :setting:`worker_consumer` |
| 166 |
``CELERY_WORKER_DIRECT`` :setting:`worker_direct` |
| 167 |
``CELERY_DISABLE_RATE_LIMITS`` :setting:`worker_disable_rate_limits` |
| 168 |
``CELERY_ENABLE_REMOTE_CONTROL`` :setting:`worker_enable_remote_control` |
| 169 |
``CELERYD_HIJACK_ROOT_LOGGER`` :setting:`worker_hijack_root_logger` |
| 170 |
``CELERYD_LOG_COLOR`` :setting:`worker_log_color` |
| 171 |
``CELERY_WORKER_LOG_FORMAT`` :setting:`worker_log_format` |
| 172 |
``CELERYD_WORKER_LOST_WAIT`` :setting:`worker_lost_wait` |
| 173 |
``CELERYD_MAX_TASKS_PER_CHILD`` :setting:`worker_max_tasks_per_child` |
| 174 |
``CELERYD_POOL`` :setting:`worker_pool` |
| 175 |
``CELERYD_POOL_PUTLOCKS`` :setting:`worker_pool_putlocks` |
| 176 |
``CELERYD_POOL_RESTARTS`` :setting:`worker_pool_restarts` |
| 177 |
``CELERYD_PREFETCH_MULTIPLIER`` :setting:`worker_prefetch_multiplier` |
| 178 |
``CELERYD_ETA_TASK_LIMIT`` :setting:`worker_eta_task_limit` |
| 179 |
``CELERYD_ENABLE_PREFETCH_COUNT_REDUCTION``:setting:`worker_enable_prefetch_count_reduction` |
| 180 |
``CELERYD_REDIRECT_STDOUTS`` :setting:`worker_redirect_stdouts` |
| 181 |
``CELERYD_REDIRECT_STDOUTS_LEVEL`` :setting:`worker_redirect_stdouts_level` |
| 182 |
``CELERY_SEND_EVENTS`` :setting:`worker_send_task_events` |
| 183 |
``CELERYD_STATE_DB`` :setting:`worker_state_db` |
| 184 |
``CELERY_WORKER_TASK_LOG_FORMAT`` :setting:`worker_task_log_format` |
| 185 |
``CELERYD_TIMER`` :setting:`worker_timer` |
| 186 |
``CELERYD_TIMER_PRECISION`` :setting:`worker_timer_precision` |
| 187 |
``CELERYD_DETECT_QUORUM_QUEUES`` :setting:`worker_detect_quorum_queues` |
| 188 |
========================================== ============================================== |
| 189 |
|
| 190 |
Configuration Directives |
| 191 |
======================== |
| 192 |
|
| 193 |
.. _conf-datetime: |
| 194 |
|
| 195 |
General settings |
| 196 |
---------------- |
| 197 |
|
| 198 |
.. setting:: accept_content |
| 199 |
|
| 200 |
``accept_content`` |
| 201 |
~~~~~~~~~~~~~~~~~~ |
| 202 |
|
| 203 |
Default: ``{'json'}`` (set, list, or tuple). |
| 204 |
|
| 205 |
A white-list of content-types/serializers to allow. |
| 206 |
|
| 207 |
If a message is received that's not in this list then |
| 208 |
the message will be discarded with an error. |
| 209 |
|
| 210 |
By default only json is enabled but any content type can be added, |
| 211 |
including pickle and yaml; when this is the case make sure |
| 212 |
untrusted parties don't have access to your broker. |
| 213 |
See :ref:`guide-security` for more. |
| 214 |
|
| 215 |
Example:: |
| 216 |
|
| 217 |
# using serializer name |
| 218 |
accept_content = ['json'] |
| 219 |
|
| 220 |
# or the actual content-type (MIME) |
| 221 |
accept_content = ['application/json'] |
| 222 |
|
| 223 |
.. setting:: result_accept_content |
| 224 |
|
| 225 |
``result_accept_content`` |
| 226 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 227 |
|
| 228 |
Default: ``None`` (can be set, list or tuple). |
| 229 |
|
| 230 |
.. versionadded:: 4.3 |
| 231 |
|
| 232 |
A white-list of content-types/serializers to allow for the result backend. |
| 233 |
|
| 234 |
If a message is received that's not in this list then |
| 235 |
the message will be discarded with an error. |
| 236 |
|
| 237 |
By default it is the same serializer as ``accept_content``. |
| 238 |
However, a different serializer for accepted content of the result backend |
| 239 |
can be specified. |
| 240 |
Usually this is needed if signed messaging is used and the result is stored |
| 241 |
unsigned in the result backend. |
| 242 |
See :ref:`guide-security` for more. |
| 243 |
|
| 244 |
Example:: |
| 245 |
|
| 246 |
# using serializer name |
| 247 |
result_accept_content = ['json'] |
| 248 |
|
| 249 |
# or the actual content-type (MIME) |
| 250 |
result_accept_content = ['application/json'] |
| 251 |
|
| 252 |
Time and date settings |
| 253 |
---------------------- |
| 254 |
|
| 255 |
.. setting:: enable_utc |
| 256 |
|
| 257 |
``enable_utc`` |
| 258 |
~~~~~~~~~~~~~~ |
| 259 |
|
| 260 |
.. versionadded:: 2.5 |
| 261 |
|
| 262 |
Default: Enabled by default since version 3.0. |
| 263 |
|
| 264 |
If enabled dates and times in messages will be converted to use |
| 265 |
the UTC timezone. |
| 266 |
|
| 267 |
Note that workers running Celery versions below 2.5 will assume a local |
| 268 |
timezone for all messages, so only enable if all workers have been |
| 269 |
upgraded. |
| 270 |
|
| 271 |
.. setting:: timezone |
| 272 |
|
| 273 |
``timezone`` |
| 274 |
~~~~~~~~~~~~ |
| 275 |
|
| 276 |
.. versionadded:: 2.5 |
| 277 |
|
| 278 |
Default: ``"UTC"``. |
| 279 |
|
| 280 |
Configure Celery to use a custom time zone. |
| 281 |
The timezone value can be any time zone supported by the `ZoneInfo <https://docs.python.org/3/library/zoneinfo.html>`_ |
| 282 |
library. |
| 283 |
|
| 284 |
If not set the UTC timezone is used. For backwards compatibility |
| 285 |
there's also a :setting:`enable_utc` setting, and when this is set |
| 286 |
to false the system local timezone is used instead. |
| 287 |
|
| 288 |
.. _conf-tasks: |
| 289 |
|
| 290 |
Task settings |
| 291 |
------------- |
| 292 |
|
| 293 |
.. setting:: task_annotations |
| 294 |
|
| 295 |
``task_annotations`` |
| 296 |
~~~~~~~~~~~~~~~~~~~~ |
| 297 |
|
| 298 |
.. versionadded:: 2.5 |
| 299 |
|
| 300 |
Default: :const:`None`. |
| 301 |
|
| 302 |
This setting can be used to rewrite any task attribute from the |
| 303 |
configuration. The setting can be a dict, or a list of annotation |
| 304 |
objects that filter for tasks and return a map of attributes |
| 305 |
to change. |
| 306 |
|
| 307 |
This will change the ``rate_limit`` attribute for the ``tasks.add`` |
| 308 |
task: |
| 309 |
|
| 310 |
.. code-block:: python |
| 311 |
|
| 312 |
task_annotations = {'tasks.add': {'rate_limit': '10/s'}} |
| 313 |
|
| 314 |
or change the same for all tasks: |
| 315 |
|
| 316 |
.. code-block:: python |
| 317 |
|
| 318 |
task_annotations = {'*': {'rate_limit': '10/s'}} |
| 319 |
|
| 320 |
You can change methods too, for example the ``on_failure`` handler: |
| 321 |
|
| 322 |
.. code-block:: python |
| 323 |
|
| 324 |
def my_on_failure(self, exc, task_id, args, kwargs, einfo): |
| 325 |
print('Oh no! Task failed: {0!r}'.format(exc)) |
| 326 |
|
| 327 |
task_annotations = {'*': {'on_failure': my_on_failure}} |
| 328 |
|
| 329 |
If you need more flexibility then you can use objects |
| 330 |
instead of a dict to choose the tasks to annotate: |
| 331 |
|
| 332 |
.. code-block:: python |
| 333 |
|
| 334 |
class MyAnnotate: |
| 335 |
|
| 336 |
def annotate(self, task): |
| 337 |
if task.name.startswith('tasks.'): |
| 338 |
return {'rate_limit': '10/s'} |
| 339 |
|
| 340 |
task_annotations = (MyAnnotate(), {other,}) |
| 341 |
|
| 342 |
.. setting:: task_compression |
| 343 |
|
| 344 |
``task_compression`` |
| 345 |
~~~~~~~~~~~~~~~~~~~~ |
| 346 |
|
| 347 |
Default: :const:`None` |
| 348 |
|
| 349 |
Default compression used for task messages. |
| 350 |
Can be ``gzip``, ``bzip2`` (if available), or any custom |
| 351 |
compression schemes registered in the Kombu compression registry. |
| 352 |
|
| 353 |
The default is to send uncompressed messages. |
| 354 |
|
| 355 |
.. setting:: task_protocol |
| 356 |
|
| 357 |
``task_protocol`` |
| 358 |
~~~~~~~~~~~~~~~~~ |
| 359 |
|
| 360 |
.. versionadded: 4.0 |
| 361 |
|
| 362 |
Default: 2 (since 4.0). |
| 363 |
|
| 364 |
Set the default task message protocol version used to send tasks. |
| 365 |
Supports protocols: 1 and 2. |
| 366 |
|
| 367 |
Protocol 2 is supported by 3.1.24 and 4.x+. |
| 368 |
|
| 369 |
.. setting:: task_serializer |
| 370 |
|
| 371 |
``task_serializer`` |
| 372 |
~~~~~~~~~~~~~~~~~~~ |
| 373 |
|
| 374 |
Default: ``"json"`` (since 4.0, earlier: pickle). |
| 375 |
|
| 376 |
A string identifying the default serialization method to use. Can be |
| 377 |
`json` (default), `pickle`, `yaml`, `msgpack`, or any custom serialization |
| 378 |
methods that have been registered with :mod:`kombu.serialization.registry`. |
| 379 |
|
| 380 |
.. seealso:: |
| 381 |
|
| 382 |
:ref:`calling-serializers`. |
| 383 |
|
| 384 |
.. setting:: task_publish_retry |
| 385 |
|
| 386 |
``task_publish_retry`` |
| 387 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 388 |
|
| 389 |
.. versionadded:: 2.2 |
| 390 |
|
| 391 |
Default: Enabled. |
| 392 |
|
| 393 |
Decides if publishing task messages will be retried in the case |
| 394 |
of connection loss or other connection errors. |
| 395 |
See also :setting:`task_publish_retry_policy`. |
| 396 |
|
| 397 |
.. setting:: task_publish_retry_policy |
| 398 |
|
| 399 |
``task_publish_retry_policy`` |
| 400 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 401 |
|
| 402 |
.. versionadded:: 2.2 |
| 403 |
|
| 404 |
Default: See :ref:`calling-retry`. |
| 405 |
|
| 406 |
Defines the default policy when retrying publishing a task message in |
| 407 |
the case of connection loss or other connection errors. |
| 408 |
|
| 409 |
.. _conf-task-execution: |
| 410 |
|
| 411 |
Task execution settings |
| 412 |
----------------------- |
| 413 |
|
| 414 |
.. setting:: task_always_eager |
| 415 |
|
| 416 |
``task_always_eager`` |
| 417 |
~~~~~~~~~~~~~~~~~~~~~ |
| 418 |
|
| 419 |
Default: Disabled. |
| 420 |
|
| 421 |
If this is :const:`True`, all tasks will be executed locally by blocking until |
| 422 |
the task returns. ``apply_async()`` and ``Task.delay()`` will return |
| 423 |
an :class:`~celery.result.EagerResult` instance, that emulates the API |
| 424 |
and behavior of :class:`~celery.result.AsyncResult`, except the result |
| 425 |
is already evaluated. |
| 426 |
|
| 427 |
That is, tasks will be executed locally instead of being sent to |
| 428 |
the queue. |
| 429 |
|
| 430 |
.. setting:: task_eager_propagates |
| 431 |
|
| 432 |
``task_eager_propagates`` |
| 433 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 434 |
|
| 435 |
Default: Disabled. |
| 436 |
|
| 437 |
If this is :const:`True`, eagerly executed tasks (applied by `task.apply()`, |
| 438 |
or when the :setting:`task_always_eager` setting is enabled), will |
| 439 |
propagate exceptions. |
| 440 |
|
| 441 |
It's the same as always running ``apply()`` with ``throw=True``. |
| 442 |
|
| 443 |
.. setting:: task_store_eager_result |
| 444 |
|
| 445 |
``task_store_eager_result`` |
| 446 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 447 |
|
| 448 |
.. versionadded:: 5.1 |
| 449 |
|
| 450 |
Default: Disabled. |
| 451 |
|
| 452 |
If this is :const:`True` and :setting:`task_always_eager` is :const:`True` |
| 453 |
and :setting:`task_ignore_result` is :const:`False`, |
| 454 |
the results of eagerly executed tasks will be saved to the backend. |
| 455 |
|
| 456 |
By default, even with :setting:`task_always_eager` set to :const:`True` |
| 457 |
and :setting:`task_ignore_result` set to :const:`False`, |
| 458 |
the result will not be saved. |
| 459 |
|
| 460 |
.. setting:: task_remote_tracebacks |
| 461 |
|
| 462 |
``task_remote_tracebacks`` |
| 463 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 464 |
|
| 465 |
Default: Disabled. |
| 466 |
|
| 467 |
If enabled task results will include the workers stack when re-raising |
| 468 |
task errors. |
| 469 |
|
| 470 |
This requires the :pypi:`tblib` library, that can be installed using |
| 471 |
:command:`pip`: |
| 472 |
|
| 473 |
.. code-block:: console |
| 474 |
|
| 475 |
$ pip install celery[tblib] |
| 476 |
|
| 477 |
See :ref:`bundles` for information on combining multiple extension |
| 478 |
requirements. |
| 479 |
|
| 480 |
.. setting:: task_ignore_result |
| 481 |
|
| 482 |
``task_ignore_result`` |
| 483 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 484 |
|
| 485 |
Default: Disabled. |
| 486 |
|
| 487 |
Whether to store the task return values or not (tombstones). |
| 488 |
If you still want to store errors, just not successful return values, |
| 489 |
you can set :setting:`task_store_errors_even_if_ignored`. |
| 490 |
|
| 491 |
.. setting:: task_store_errors_even_if_ignored |
| 492 |
|
| 493 |
``task_store_errors_even_if_ignored`` |
| 494 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 495 |
|
| 496 |
Default: Disabled. |
| 497 |
|
| 498 |
If set, the worker stores all task errors in the result store even if |
| 499 |
:attr:`Task.ignore_result <celery.app.task.Task.ignore_result>` is on. |
| 500 |
|
| 501 |
.. setting:: task_track_started |
| 502 |
|
| 503 |
``task_track_started`` |
| 504 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 505 |
|
| 506 |
Default: Disabled. |
| 507 |
|
| 508 |
If :const:`True` the task will report its status as 'started' when the |
| 509 |
task is executed by a worker. The default value is :const:`False` as |
| 510 |
the normal behavior is to not report that level of granularity. Tasks |
| 511 |
are either pending, finished, or waiting to be retried. Having a 'started' |
| 512 |
state can be useful for when there are long running tasks and there's a |
| 513 |
need to report what task is currently running. |
| 514 |
|
| 515 |
.. setting:: task_time_limit |
| 516 |
|
| 517 |
``task_time_limit`` |
| 518 |
~~~~~~~~~~~~~~~~~~~ |
| 519 |
|
| 520 |
Default: No time limit. |
| 521 |
|
| 522 |
Task hard time limit in seconds. The worker processing the task will |
| 523 |
be killed and replaced with a new one when this is exceeded. |
| 524 |
|
| 525 |
.. setting:: task_allow_error_cb_on_chord_header |
| 526 |
|
| 527 |
``task_allow_error_cb_on_chord_header`` |
| 528 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 529 |
|
| 530 |
.. versionadded:: 5.3 |
| 531 |
|
| 532 |
Default: Disabled. |
| 533 |
|
| 534 |
Enabling this flag will allow linking an error callback to a chord header, |
| 535 |
which by default will not link when using :code:`link_error()`, and preventing |
| 536 |
from the chord's body to execute if any of the tasks in the header fails. |
| 537 |
|
| 538 |
Consider the following canvas with the flag disabled (default behavior): |
| 539 |
|
| 540 |
.. code-block:: python |
| 541 |
|
| 542 |
header = group([t1, t2]) |
| 543 |
body = t3 |
| 544 |
c = chord(header, body) |
| 545 |
c.link_error(error_callback_sig) |
| 546 |
|
| 547 |
If *any* of the header tasks failed (:code:`t1` or :code:`t2`), by default, the chord body (:code:`t3`) would **not execute**, and :code:`error_callback_sig` will be called **once** (for the body). |
| 548 |
|
| 549 |
Enabling this flag will change the above behavior by: |
| 550 |
|
| 551 |
1. :code:`error_callback_sig` will be linked to :code:`t1` and :code:`t2` (as well as :code:`t3`). |
| 552 |
2. If *any* of the header tasks failed, :code:`error_callback_sig` will be called **for each** failed header task **and** the :code:`body` (even if the body didn't run). |
| 553 |
|
| 554 |
Consider now the following canvas with the flag enabled: |
| 555 |
|
| 556 |
.. code-block:: python |
| 557 |
|
| 558 |
header = group([failingT1, failingT2]) |
| 559 |
body = t3 |
| 560 |
c = chord(header, body) |
| 561 |
c.link_error(error_callback_sig) |
| 562 |
|
| 563 |
If *all* of the header tasks failed (:code:`failingT1` and :code:`failingT2`), then the chord body (:code:`t3`) would **not execute**, and :code:`error_callback_sig` will be called **3 times** (two times for the header and one time for the body). |
| 564 |
|
| 565 |
Lastly, consider the following canvas with the flag enabled: |
| 566 |
|
| 567 |
.. code-block:: python |
| 568 |
|
| 569 |
header = group([failingT1, failingT2]) |
| 570 |
body = t3 |
| 571 |
upgraded_chord = chain(header, body) |
| 572 |
upgraded_chord.link_error(error_callback_sig) |
| 573 |
|
| 574 |
This canvas will behave exactly the same as the previous one, since the :code:`chain` will be upgraded to a :code:`chord` internally. |
| 575 |
|
| 576 |
.. setting:: task_soft_time_limit |
| 577 |
|
| 578 |
``task_soft_time_limit`` |
| 579 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 580 |
|
| 581 |
Default: No soft time limit. |
| 582 |
|
| 583 |
Task soft time limit in seconds. |
| 584 |
|
| 585 |
The :exc:`~@SoftTimeLimitExceeded` exception will be |
| 586 |
raised when this is exceeded. For example, the task can catch this to |
| 587 |
clean up before the hard time limit comes: |
| 588 |
|
| 589 |
.. code-block:: python |
| 590 |
|
| 591 |
from celery.exceptions import SoftTimeLimitExceeded |
| 592 |
|
| 593 |
@app.task |
| 594 |
def mytask(): |
| 595 |
try: |
| 596 |
return do_work() |
| 597 |
except SoftTimeLimitExceeded: |
| 598 |
cleanup_in_a_hurry() |
| 599 |
|
| 600 |
.. setting:: task_acks_late |
| 601 |
|
| 602 |
``task_acks_late`` |
| 603 |
~~~~~~~~~~~~~~~~~~ |
| 604 |
|
| 605 |
Default: Disabled. |
| 606 |
|
| 607 |
Late ack means the task messages will be acknowledged **after** the task |
| 608 |
has been executed, not *right before* (the default behavior). |
| 609 |
|
| 610 |
.. seealso:: |
| 611 |
|
| 612 |
FAQ: :ref:`faq-acks_late-vs-retry`. |
| 613 |
|
| 614 |
.. setting:: task_acks_on_failure_or_timeout |
| 615 |
|
| 616 |
``task_acks_on_failure_or_timeout`` |
| 617 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 618 |
|
| 619 |
Default: Enabled |
| 620 |
|
| 621 |
When enabled messages for all tasks will be acknowledged even if they |
| 622 |
fail or time out. |
| 623 |
|
| 624 |
Configuring this setting only applies to tasks that are |
| 625 |
acknowledged **after** they have been executed and only if |
| 626 |
:setting:`task_acks_late` is enabled. |
| 627 |
|
| 628 |
.. setting:: task_reject_on_worker_lost |
| 629 |
|
| 630 |
``task_reject_on_worker_lost`` |
| 631 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 632 |
|
| 633 |
Default: Disabled. |
| 634 |
|
| 635 |
Even if :setting:`task_acks_late` is enabled, the worker will |
| 636 |
acknowledge tasks when the worker process executing them abruptly |
| 637 |
exits or is signaled (e.g., :sig:`KILL`/:sig:`INT`, etc). |
| 638 |
|
| 639 |
Setting this to true allows the message to be re-queued instead, |
| 640 |
so that the task will execute again by the same worker, or another |
| 641 |
worker. |
| 642 |
|
| 643 |
.. warning:: |
| 644 |
|
| 645 |
Enabling this can cause message loops; make sure you know |
| 646 |
what you're doing. |
| 647 |
|
| 648 |
.. setting:: task_default_rate_limit |
| 649 |
|
| 650 |
``task_default_rate_limit`` |
| 651 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 652 |
|
| 653 |
Default: No rate limit. |
| 654 |
|
| 655 |
The global default rate limit for tasks. |
| 656 |
|
| 657 |
This value is used for tasks that doesn't have a custom rate limit |
| 658 |
|
| 659 |
.. seealso:: |
| 660 |
|
| 661 |
The :setting:`worker_disable_rate_limits` setting can |
| 662 |
disable all rate limits. |
| 663 |
|
| 664 |
.. _conf-result-backend: |
| 665 |
|
| 666 |
Task result backend settings |
| 667 |
---------------------------- |
| 668 |
|
| 669 |
.. setting:: result_backend |
| 670 |
|
| 671 |
``result_backend`` |
| 672 |
~~~~~~~~~~~~~~~~~~ |
| 673 |
|
| 674 |
Default: No result backend enabled by default. |
| 675 |
|
| 676 |
The backend used to store task results (tombstones). |
| 677 |
Can be one of the following: |
| 678 |
|
| 679 |
* ``rpc`` |
| 680 |
Send results back as AMQP messages |
| 681 |
See :ref:`conf-rpc-result-backend`. |
| 682 |
|
| 683 |
* ``database`` |
| 684 |
Use a relational database supported by `SQLAlchemy`_. |
| 685 |
See :ref:`conf-database-result-backend`. |
| 686 |
|
| 687 |
* ``redis`` |
| 688 |
Use `Redis`_ to store the results. |
| 689 |
See :ref:`conf-redis-result-backend`. |
| 690 |
|
| 691 |
* ``cache`` |
| 692 |
Use `Memcached`_ to store the results. |
| 693 |
See :ref:`conf-cache-result-backend`. |
| 694 |
|
| 695 |
* ``mongodb`` |
| 696 |
Use `MongoDB`_ to store the results. |
| 697 |
See :ref:`conf-mongodb-result-backend`. |
| 698 |
|
| 699 |
* ``cassandra`` |
| 700 |
Use `Cassandra`_ to store the results. |
| 701 |
See :ref:`conf-cassandra-result-backend`. |
| 702 |
|
| 703 |
* ``elasticsearch`` |
| 704 |
Use `Elasticsearch`_ to store the results. |
| 705 |
See :ref:`conf-elasticsearch-result-backend`. |
| 706 |
|
| 707 |
* ``ironcache`` |
| 708 |
Use `IronCache`_ to store the results. |
| 709 |
See :ref:`conf-ironcache-result-backend`. |
| 710 |
|
| 711 |
* ``couchbase`` |
| 712 |
Use `Couchbase`_ to store the results. |
| 713 |
See :ref:`conf-couchbase-result-backend`. |
| 714 |
|
| 715 |
* ``arangodb`` |
| 716 |
Use `ArangoDB`_ to store the results. |
| 717 |
See :ref:`conf-arangodb-result-backend`. |
| 718 |
|
| 719 |
* ``couchdb`` |
| 720 |
Use `CouchDB`_ to store the results. |
| 721 |
See :ref:`conf-couchdb-result-backend`. |
| 722 |
|
| 723 |
* ``cosmosdbsql (experimental)`` |
| 724 |
Use the `CosmosDB`_ PaaS to store the results. |
| 725 |
See :ref:`conf-cosmosdbsql-result-backend`. |
| 726 |
|
| 727 |
* ``filesystem`` |
| 728 |
Use a shared directory to store the results. |
| 729 |
See :ref:`conf-filesystem-result-backend`. |
| 730 |
|
| 731 |
* ``consul`` |
| 732 |
Use the `Consul`_ K/V store to store the results |
| 733 |
See :ref:`conf-consul-result-backend`. |
| 734 |
|
| 735 |
* ``azureblockblob`` |
| 736 |
Use the `AzureBlockBlob`_ PaaS store to store the results |
| 737 |
See :ref:`conf-azureblockblob-result-backend`. |
| 738 |
|
| 739 |
* ``s3`` |
| 740 |
Use the `S3`_ to store the results |
| 741 |
See :ref:`conf-s3-result-backend`. |
| 742 |
|
| 743 |
* ``gcs`` |
| 744 |
Use the `GCS`_ to store the results |
| 745 |
See :ref:`conf-gcs-result-backend`. |
| 746 |
|
| 747 |
.. warning: |
| 748 |
|
| 749 |
While the AMQP result backend is very efficient, you must make sure |
| 750 |
you only receive the same result once. See :doc:`userguide/calling`). |
| 751 |
|
| 752 |
.. _`SQLAlchemy`: http://sqlalchemy.org |
| 753 |
.. _`Memcached`: http://memcached.org |
| 754 |
.. _`MongoDB`: http://mongodb.org |
| 755 |
.. _`Redis`: https://redis.io |
| 756 |
.. _`Cassandra`: http://cassandra.apache.org/ |
| 757 |
.. _`Elasticsearch`: https://aws.amazon.com/elasticsearch-service/ |
| 758 |
.. _`IronCache`: http://www.iron.io/cache |
| 759 |
.. _`CouchDB`: http://www.couchdb.com/ |
| 760 |
.. _`CosmosDB`: https://azure.microsoft.com/en-us/services/cosmos-db/ |
| 761 |
.. _`Couchbase`: https://www.couchbase.com/ |
| 762 |
.. _`ArangoDB`: https://www.arangodb.com/ |
| 763 |
.. _`Consul`: https://consul.io/ |
| 764 |
.. _`AzureBlockBlob`: https://azure.microsoft.com/en-us/services/storage/blobs/ |
| 765 |
.. _`S3`: https://aws.amazon.com/s3/ |
| 766 |
.. _`GCS`: https://cloud.google.com/storage/ |
| 767 |
.. _`RedisCredentialProvider`: https://redis.readthedocs.io/en/stable/examples/connection_examples.html#Connecting-to-a-redis-instance-with-standard-credential-provider |
| 768 |
|
| 769 |
|
| 770 |
.. setting:: result_backend_always_retry |
| 771 |
|
| 772 |
``result_backend_always_retry`` |
| 773 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 774 |
|
| 775 |
Default: :const:`False` |
| 776 |
|
| 777 |
If enable, backend will try to retry on the event of recoverable exceptions instead of propagating the exception. |
| 778 |
It will use an exponential backoff sleep time between 2 retries. |
| 779 |
|
| 780 |
|
| 781 |
.. setting:: result_backend_max_sleep_between_retries_ms |
| 782 |
|
| 783 |
``result_backend_max_sleep_between_retries_ms`` |
| 784 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 785 |
|
| 786 |
Default: 10000 |
| 787 |
|
| 788 |
This specifies the maximum sleep time between two backend operation retry. |
| 789 |
|
| 790 |
|
| 791 |
.. setting:: result_backend_base_sleep_between_retries_ms |
| 792 |
|
| 793 |
``result_backend_base_sleep_between_retries_ms`` |
| 794 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 795 |
|
| 796 |
Default: 10 |
| 797 |
|
| 798 |
This specifies the base amount of sleep time between two backend operation retry. |
| 799 |
|
| 800 |
|
| 801 |
.. setting:: result_backend_max_retries |
| 802 |
|
| 803 |
``result_backend_max_retries`` |
| 804 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 805 |
|
| 806 |
Default: Inf |
| 807 |
|
| 808 |
This is the maximum of retries in case of recoverable exceptions. |
| 809 |
|
| 810 |
|
| 811 |
.. setting:: result_backend_thread_safe |
| 812 |
|
| 813 |
``result_backend_thread_safe`` |
| 814 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 815 |
|
| 816 |
Default: False |
| 817 |
|
| 818 |
If True, then the backend object is shared across threads. |
| 819 |
This may be useful for using a shared connection pool instead of creating |
| 820 |
a connection for every thread. |
| 821 |
|
| 822 |
|
| 823 |
.. setting:: result_backend_transport_options |
| 824 |
|
| 825 |
``result_backend_transport_options`` |
| 826 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 827 |
|
| 828 |
Default: ``{}`` (empty mapping). |
| 829 |
|
| 830 |
A dict of additional options passed to the underlying transport. |
| 831 |
|
| 832 |
See your transport user manual for supported options (if any). |
| 833 |
|
| 834 |
Example setting the visibility timeout (supported by Redis and SQS |
| 835 |
transports): |
| 836 |
|
| 837 |
.. code-block:: python |
| 838 |
|
| 839 |
result_backend_transport_options = {'visibility_timeout': 18000} # 5 hours |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
.. setting:: result_serializer |
| 844 |
|
| 845 |
``result_serializer`` |
| 846 |
~~~~~~~~~~~~~~~~~~~~~ |
| 847 |
|
| 848 |
Default: ``json`` since 4.0 (earlier: pickle). |
| 849 |
|
| 850 |
Result serialization format. |
| 851 |
|
| 852 |
See :ref:`calling-serializers` for information about supported |
| 853 |
serialization formats. |
| 854 |
|
| 855 |
.. setting:: result_compression |
| 856 |
|
| 857 |
``result_compression`` |
| 858 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 859 |
|
| 860 |
Default: No compression. |
| 861 |
|
| 862 |
Optional compression method used for task results. |
| 863 |
Supports the same options as the :setting:`task_compression` setting. |
| 864 |
|
| 865 |
.. setting:: result_extended |
| 866 |
|
| 867 |
``result_extended`` |
| 868 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 869 |
|
| 870 |
Default: ``False`` |
| 871 |
|
| 872 |
Enables extended task result attributes (name, args, kwargs, worker, |
| 873 |
retries, queue, delivery_info) to be written to backend. |
| 874 |
|
| 875 |
.. setting:: result_expires |
| 876 |
|
| 877 |
``result_expires`` |
| 878 |
~~~~~~~~~~~~~~~~~~ |
| 879 |
|
| 880 |
Default: Expire after 1 day. |
| 881 |
|
| 882 |
Time (in seconds, or a :class:`~datetime.timedelta` object) for when after |
| 883 |
stored task tombstones will be deleted. |
| 884 |
|
| 885 |
A built-in periodic task will delete the results after this time |
| 886 |
(``celery.backend_cleanup``), assuming that ``celery beat`` is |
| 887 |
enabled. The task runs daily at 4am. |
| 888 |
|
| 889 |
A value of :const:`None` or 0 means results will never expire (depending |
| 890 |
on backend specifications). |
| 891 |
|
| 892 |
.. note:: |
| 893 |
|
| 894 |
For the moment this only works with the AMQP, database, cache, Couchbase, |
| 895 |
filesystem and Redis backends. |
| 896 |
|
| 897 |
When using the database or filesystem backend, ``celery beat`` must be |
| 898 |
running for the results to be expired. |
| 899 |
|
| 900 |
.. setting:: result_cache_max |
| 901 |
|
| 902 |
``result_cache_max`` |
| 903 |
~~~~~~~~~~~~~~~~~~~~ |
| 904 |
|
| 905 |
Default: Disabled by default. |
| 906 |
|
| 907 |
Enables client caching of results. |
| 908 |
|
| 909 |
This can be useful for the old deprecated |
| 910 |
'amqp' backend where the result is unavailable as soon as one result instance |
| 911 |
consumes it. |
| 912 |
|
| 913 |
This is the total number of results to cache before older results are evicted. |
| 914 |
A value of 0 or None means no limit, and a value of :const:`-1` |
| 915 |
will disable the cache. |
| 916 |
|
| 917 |
Disabled by default. |
| 918 |
|
| 919 |
.. setting:: result_chord_join_timeout |
| 920 |
|
| 921 |
``result_chord_join_timeout`` |
| 922 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 923 |
|
| 924 |
Default: 3.0. |
| 925 |
|
| 926 |
The timeout in seconds (int/float) when joining a group's results within a chord. |
| 927 |
|
| 928 |
.. setting:: result_chord_retry_interval |
| 929 |
|
| 930 |
``result_chord_retry_interval`` |
| 931 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 932 |
|
| 933 |
Default: 1.0. |
| 934 |
|
| 935 |
Default interval for retrying chord tasks. |
| 936 |
|
| 937 |
.. setting:: override_backends |
| 938 |
|
| 939 |
``override_backends`` |
| 940 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 941 |
|
| 942 |
Default: Disabled by default. |
| 943 |
|
| 944 |
Path to class that implements backend. |
| 945 |
|
| 946 |
Allows to override backend implementation. |
| 947 |
This can be useful if you need to store additional metadata about executed tasks, |
| 948 |
override retry policies, etc. |
| 949 |
|
| 950 |
Example: |
| 951 |
|
| 952 |
.. code-block:: python |
| 953 |
|
| 954 |
override_backends = {"db": "custom_module.backend.class"} |
| 955 |
|
| 956 |
.. _conf-database-result-backend: |
| 957 |
|
| 958 |
Database backend settings |
| 959 |
------------------------- |
| 960 |
|
| 961 |
Database URL Examples |
| 962 |
~~~~~~~~~~~~~~~~~~~~~ |
| 963 |
|
| 964 |
To use the database backend you have to configure the |
| 965 |
:setting:`result_backend` setting with a connection URL and the ``db+`` |
| 966 |
prefix: |
| 967 |
|
| 968 |
.. code-block:: python |
| 969 |
|
| 970 |
result_backend = 'db+scheme://user:password@host:port/dbname' |
| 971 |
|
| 972 |
Examples:: |
| 973 |
|
| 974 |
# sqlite (filename) |
| 975 |
result_backend = 'db+sqlite:///results.sqlite' |
| 976 |
|
| 977 |
# mysql |
| 978 |
result_backend = 'db+mysql://scott:tiger@localhost/foo' |
| 979 |
|
| 980 |
# postgresql |
| 981 |
result_backend = 'db+postgresql://scott:tiger@localhost/mydatabase' |
| 982 |
|
| 983 |
# oracle |
| 984 |
result_backend = 'db+oracle://scott:[email protected]:1521/sidname' |
| 985 |
|
| 986 |
.. code-block:: python |
| 987 |
|
| 988 |
Please see `Supported Databases`_ for a table of supported databases, |
| 989 |
and `Connection String`_ for more information about connection |
| 990 |
strings (this is the part of the URI that comes after the ``db+`` prefix). |
| 991 |
|
| 992 |
.. _`Supported Databases`: |
| 993 |
http://www.sqlalchemy.org/docs/core/engines.html#supported-databases |
| 994 |
|
| 995 |
.. _`Connection String`: |
| 996 |
http://www.sqlalchemy.org/docs/core/engines.html#database-urls |
| 997 |
|
| 998 |
.. note:: |
| 999 |
|
| 1000 |
If you are upgrading from Celery 5.6 or earlier, the ``date_done`` column |
| 1001 |
in ``celery_taskmeta`` and ``celery_tasksetmeta`` tables does not have a |
| 1002 |
database index. The built-in periodic task ``celery.backend_cleanup`` |
| 1003 |
queries on ``date_done`` to delete expired task results, so adding an |
| 1004 |
index significantly improves cleanup performance on large tables. |
| 1005 |
|
| 1006 |
Since SQLAlchemy's ``create_all()`` will not alter existing tables, you |
| 1007 |
will need to update your database schema. If you are using Alembic for |
| 1008 |
schema migrations, you can generate an empty revision and apply the |
| 1009 |
following operations: |
| 1010 |
|
| 1011 |
.. code-block:: python |
| 1012 |
|
| 1013 |
from alembic import op |
| 1014 |
|
| 1015 |
def upgrade(): |
| 1016 |
op.create_index('ix_celery_taskmeta_date_done', 'celery_taskmeta', ['date_done']) |
| 1017 |
op.create_index('ix_celery_tasksetmeta_date_done', 'celery_tasksetmeta', ['date_done']) |
| 1018 |
|
| 1019 |
def downgrade(): |
| 1020 |
op.drop_index('ix_celery_tasksetmeta_date_done', table_name='celery_tasksetmeta') |
| 1021 |
op.drop_index('ix_celery_taskmeta_date_done', table_name='celery_taskmeta') |
| 1022 |
|
| 1023 |
Otherwise, you can add the indexes manually using SQL: |
| 1024 |
|
| 1025 |
.. code-block:: sql |
| 1026 |
|
| 1027 |
CREATE INDEX ix_celery_taskmeta_date_done ON celery_taskmeta (date_done); |
| 1028 |
CREATE INDEX ix_celery_tasksetmeta_date_done ON celery_tasksetmeta (date_done); |
| 1029 |
|
| 1030 |
.. setting:: database_create_tables_at_setup |
| 1031 |
|
| 1032 |
``database_create_tables_at_setup`` |
| 1033 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1034 |
|
| 1035 |
.. versionadded:: 5.5.0 |
| 1036 |
|
| 1037 |
Default: True by default. |
| 1038 |
|
| 1039 |
- If `True`, Celery will create the tables in the database during setup. |
| 1040 |
- If `False`, Celery will create the tables lazily, i.e. wait for the first task |
| 1041 |
to be executed before creating the tables. |
| 1042 |
|
| 1043 |
.. note:: |
| 1044 |
Before celery 5.5, the tables were created lazily i.e. it was equivalent to |
| 1045 |
`database_create_tables_at_setup` set to False. |
| 1046 |
|
| 1047 |
.. setting:: database_engine_options |
| 1048 |
|
| 1049 |
``database_engine_options`` |
| 1050 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1051 |
|
| 1052 |
Default: ``{'pool_pre_ping': True, 'pool_recycle': 3600}`` |
| 1053 |
|
| 1054 |
.. versionchanged:: 5.7 |
| 1055 |
|
| 1056 |
The default was changed from ``{}`` to include ``pool_pre_ping=True`` |
| 1057 |
and ``pool_recycle=3600`` for improved connection health handling. |
| 1058 |
This helps prevent stale connection errors such as |
| 1059 |
``(OperationalError) (2006, 'MySQL server has gone away')``. |
| 1060 |
|
| 1061 |
To specify additional SQLAlchemy database engine options you can use |
| 1062 |
the :setting:`database_engine_options` setting:: |
| 1063 |
|
| 1064 |
# echo enables verbose logging from SQLAlchemy. |
| 1065 |
app.conf.database_engine_options = {'echo': True} |
| 1066 |
|
| 1067 |
# To disable the default pool health options: |
| 1068 |
app.conf.database_engine_options = {'pool_pre_ping': False, 'pool_recycle': None} |
| 1069 |
|
| 1070 |
.. setting:: database_short_lived_sessions |
| 1071 |
|
| 1072 |
``database_short_lived_sessions`` |
| 1073 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1074 |
|
| 1075 |
Default: Disabled by default. |
| 1076 |
|
| 1077 |
Short lived sessions are disabled by default. If enabled they can drastically reduce |
| 1078 |
performance, especially on systems processing lots of tasks. This option is useful |
| 1079 |
on low-traffic workers that experience errors as a result of cached database connections |
| 1080 |
going stale through inactivity. For example, intermittent errors like |
| 1081 |
`(OperationalError) (2006, 'MySQL server has gone away')` can be fixed by enabling |
| 1082 |
short lived sessions. This option only affects the database backend. |
| 1083 |
|
| 1084 |
.. setting:: database_table_schemas |
| 1085 |
|
| 1086 |
``database_table_schemas`` |
| 1087 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1088 |
|
| 1089 |
Default: ``{}`` (empty mapping). |
| 1090 |
|
| 1091 |
When SQLAlchemy is configured as the result backend, Celery automatically |
| 1092 |
creates two tables to store result meta-data for tasks. This setting allows |
| 1093 |
you to customize the schema of the tables: |
| 1094 |
|
| 1095 |
.. code-block:: python |
| 1096 |
|
| 1097 |
# use custom schema for the database result backend. |
| 1098 |
database_table_schemas = { |
| 1099 |
'task': 'celery', |
| 1100 |
'group': 'celery', |
| 1101 |
} |
| 1102 |
|
| 1103 |
.. setting:: database_table_names |
| 1104 |
|
| 1105 |
``database_table_names`` |
| 1106 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1107 |
|
| 1108 |
Default: ``{}`` (empty mapping). |
| 1109 |
|
| 1110 |
When SQLAlchemy is configured as the result backend, Celery automatically |
| 1111 |
creates two tables to store result meta-data for tasks. This setting allows |
| 1112 |
you to customize the table names: |
| 1113 |
|
| 1114 |
.. code-block:: python |
| 1115 |
|
| 1116 |
# use custom table names for the database result backend. |
| 1117 |
database_table_names = { |
| 1118 |
'task': 'myapp_taskmeta', |
| 1119 |
'group': 'myapp_groupmeta', |
| 1120 |
} |
| 1121 |
|
| 1122 |
.. _conf-rpc-result-backend: |
| 1123 |
|
| 1124 |
RPC backend settings |
| 1125 |
-------------------- |
| 1126 |
|
| 1127 |
.. setting:: result_persistent |
| 1128 |
|
| 1129 |
``result_persistent`` |
| 1130 |
~~~~~~~~~~~~~~~~~~~~~ |
| 1131 |
|
| 1132 |
Default: Disabled by default (transient messages). |
| 1133 |
|
| 1134 |
If set to :const:`True`, result messages will be persistent. This means the |
| 1135 |
messages won't be lost after a broker restart. |
| 1136 |
|
| 1137 |
Example configuration |
| 1138 |
~~~~~~~~~~~~~~~~~~~~~ |
| 1139 |
|
| 1140 |
.. code-block:: python |
| 1141 |
|
| 1142 |
result_backend = 'rpc://' |
| 1143 |
result_persistent = False |
| 1144 |
|
| 1145 |
**Please note**: using this backend could trigger the raise of ``celery.backends.rpc.BacklogLimitExceeded`` if the task tombstone is too *old*. |
| 1146 |
|
| 1147 |
E.g. |
| 1148 |
|
| 1149 |
.. code-block:: python |
| 1150 |
|
| 1151 |
for i in range(10000): |
| 1152 |
r = debug_task.delay() |
| 1153 |
|
| 1154 |
print(r.state) # this would raise celery.backends.rpc.BacklogLimitExceeded |
| 1155 |
|
| 1156 |
.. _conf-cache-result-backend: |
| 1157 |
|
| 1158 |
Cache backend settings |
| 1159 |
---------------------- |
| 1160 |
|
| 1161 |
.. note:: |
| 1162 |
|
| 1163 |
The cache backend supports the :pypi:`pylibmc` and :pypi:`python-memcached` |
| 1164 |
libraries. The latter is used only if :pypi:`pylibmc` isn't installed. |
| 1165 |
|
| 1166 |
Using a single Memcached server: |
| 1167 |
|
| 1168 |
.. code-block:: python |
| 1169 |
|
| 1170 |
result_backend = 'cache+memcached://127.0.0.1:11211/' |
| 1171 |
|
| 1172 |
Using multiple Memcached servers: |
| 1173 |
|
| 1174 |
.. code-block:: python |
| 1175 |
|
| 1176 |
result_backend = """ |
| 1177 |
cache+memcached://172.19.26.240:11211;172.19.26.242:11211/ |
| 1178 |
""".strip() |
| 1179 |
|
| 1180 |
The "memory" backend stores the cache in memory only: |
| 1181 |
|
| 1182 |
.. code-block:: python |
| 1183 |
|
| 1184 |
result_backend = 'cache' |
| 1185 |
cache_backend = 'memory' |
| 1186 |
|
| 1187 |
.. setting:: cache_backend_options |
| 1188 |
|
| 1189 |
``cache_backend_options`` |
| 1190 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1191 |
|
| 1192 |
Default: ``{}`` (empty mapping). |
| 1193 |
|
| 1194 |
You can set :pypi:`pylibmc` options using the :setting:`cache_backend_options` |
| 1195 |
setting: |
| 1196 |
|
| 1197 |
.. code-block:: python |
| 1198 |
|
| 1199 |
cache_backend_options = { |
| 1200 |
'binary': True, |
| 1201 |
'behaviors': {'tcp_nodelay': True}, |
| 1202 |
} |
| 1203 |
|
| 1204 |
.. setting:: cache_backend |
| 1205 |
|
| 1206 |
``cache_backend`` |
| 1207 |
~~~~~~~~~~~~~~~~~ |
| 1208 |
|
| 1209 |
This setting is no longer used in celery's builtin backends as it's now possible to specify |
| 1210 |
the cache backend directly in the :setting:`result_backend` setting. |
| 1211 |
|
| 1212 |
.. note:: |
| 1213 |
|
| 1214 |
The :ref:`django-celery-results` library uses ``cache_backend`` for choosing django caches. |
| 1215 |
|
| 1216 |
.. _conf-mongodb-result-backend: |
| 1217 |
|
| 1218 |
MongoDB backend settings |
| 1219 |
------------------------ |
| 1220 |
|
| 1221 |
.. note:: |
| 1222 |
|
| 1223 |
The MongoDB backend requires the :mod:`pymongo` library: |
| 1224 |
http://github.com/mongodb/mongo-python-driver/tree/master |
| 1225 |
|
| 1226 |
.. setting:: mongodb_backend_settings |
| 1227 |
|
| 1228 |
mongodb_backend_settings |
| 1229 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1230 |
|
| 1231 |
This is a dict supporting the following keys: |
| 1232 |
|
| 1233 |
* database |
| 1234 |
The database name to connect to. Defaults to ``celery``. |
| 1235 |
|
| 1236 |
* taskmeta_collection |
| 1237 |
The collection name to store task meta data. |
| 1238 |
Defaults to ``celery_taskmeta``. |
| 1239 |
|
| 1240 |
* max_pool_size |
| 1241 |
Passed as max_pool_size to PyMongo's Connection or MongoClient |
| 1242 |
constructor. It is the maximum number of TCP connections to keep |
| 1243 |
open to MongoDB at a given time. If there are more open connections |
| 1244 |
than max_pool_size, sockets will be closed when they are released. |
| 1245 |
Defaults to 10. |
| 1246 |
|
| 1247 |
* options |
| 1248 |
|
| 1249 |
Additional keyword arguments to pass to the mongodb connection |
| 1250 |
constructor. See the :mod:`pymongo` docs to see a list of arguments |
| 1251 |
supported. |
| 1252 |
|
| 1253 |
.. note:: |
| 1254 |
|
| 1255 |
With pymongo>=4.14, options are case-sensitive when they were previously |
| 1256 |
case-insensitive. See :class:`~pymongo.mongo_client.MongoClient` to |
| 1257 |
determine the correct case. |
| 1258 |
|
| 1259 |
.. _example-mongodb-result-config: |
| 1260 |
|
| 1261 |
Example configuration |
| 1262 |
~~~~~~~~~~~~~~~~~~~~~ |
| 1263 |
|
| 1264 |
.. code-block:: python |
| 1265 |
|
| 1266 |
result_backend = 'mongodb://localhost:27017/' |
| 1267 |
mongodb_backend_settings = { |
| 1268 |
'database': 'mydb', |
| 1269 |
'taskmeta_collection': 'my_taskmeta_collection', |
| 1270 |
} |
| 1271 |
|
| 1272 |
.. _conf-redis-result-backend: |
| 1273 |
|
| 1274 |
Redis backend settings |
| 1275 |
---------------------- |
| 1276 |
|
| 1277 |
Configuring the backend URL |
| 1278 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1279 |
|
| 1280 |
.. note:: |
| 1281 |
|
| 1282 |
The Redis backend requires the :pypi:`redis` library. |
| 1283 |
|
| 1284 |
To install this package use :command:`pip`: |
| 1285 |
|
| 1286 |
.. code-block:: console |
| 1287 |
|
| 1288 |
$ pip install celery[redis] |
| 1289 |
|
| 1290 |
See :ref:`bundles` for information on combining multiple extension |
| 1291 |
requirements. |
| 1292 |
|
| 1293 |
This backend requires the :setting:`result_backend` |
| 1294 |
setting to be set to a Redis or `Redis over TLS`_ URL:: |
| 1295 |
|
| 1296 |
result_backend = 'redis://username:password@host:port/db' |
| 1297 |
|
| 1298 |
.. _`Redis over TLS`: |
| 1299 |
https://www.iana.org/assignments/uri-schemes/prov/rediss |
| 1300 |
|
| 1301 |
For example:: |
| 1302 |
|
| 1303 |
result_backend = 'redis://localhost/0' |
| 1304 |
|
| 1305 |
is the same as:: |
| 1306 |
|
| 1307 |
result_backend = 'redis://' |
| 1308 |
|
| 1309 |
Use the ``rediss://`` protocol to connect to redis over TLS:: |
| 1310 |
|
| 1311 |
result_backend = 'rediss://username:password@host:port/db?ssl_cert_reqs=required' |
| 1312 |
|
| 1313 |
Note that the ``ssl_cert_reqs`` string should be one of ``required``, |
| 1314 |
``optional``, or ``none`` (though, for backwards compatibility with older Celery versions, the string |
| 1315 |
may also be one of ``CERT_REQUIRED``, ``CERT_OPTIONAL``, ``CERT_NONE``, but those values |
| 1316 |
only work for Celery, not for Redis directly). |
| 1317 |
|
| 1318 |
If a Unix socket connection should be used, the URL needs to be in the format::: |
| 1319 |
|
| 1320 |
result_backend = 'socket:///path/to/redis.sock' |
| 1321 |
|
| 1322 |
The fields of the URL are defined as follows: |
| 1323 |
|
| 1324 |
#. ``username`` |
| 1325 |
|
| 1326 |
.. versionadded:: 5.1.0 |
| 1327 |
|
| 1328 |
Username used to connect to the database. |
| 1329 |
|
| 1330 |
Note that this is only supported in Redis>=6.0 and with py-redis>=3.4.0 |
| 1331 |
installed. |
| 1332 |
|
| 1333 |
If you use an older database version or an older client version |
| 1334 |
you can omit the username:: |
| 1335 |
|
| 1336 |
result_backend = 'redis://:password@host:port/db' |
| 1337 |
|
| 1338 |
#. ``password`` |
| 1339 |
|
| 1340 |
Password used to connect to the database. |
| 1341 |
|
| 1342 |
#. ``host`` |
| 1343 |
|
| 1344 |
Host name or IP address of the Redis server (e.g., `localhost`). |
| 1345 |
|
| 1346 |
#. ``port`` |
| 1347 |
|
| 1348 |
Port to the Redis server. Default is 6379. |
| 1349 |
|
| 1350 |
#. ``db`` |
| 1351 |
|
| 1352 |
Database number to use. Default is 0. |
| 1353 |
The db can include an optional leading slash. |
| 1354 |
|
| 1355 |
When using a TLS connection (protocol is ``rediss://``), you may pass in all values in :setting:`broker_use_ssl` as query parameters. Paths to certificates must be URL encoded, and ``ssl_cert_reqs`` is required. Example: |
| 1356 |
|
| 1357 |
.. code-block:: python |
| 1358 |
|
| 1359 |
result_backend = 'rediss://:password@host:port/db?\ |
| 1360 |
ssl_cert_reqs=required\ |
| 1361 |
&ssl_ca_certs=%2Fvar%2Fssl%2Fmyca.pem\ # /var/ssl/myca.pem |
| 1362 |
&ssl_certfile=%2Fvar%2Fssl%2Fredis-server-cert.pem\ # /var/ssl/redis-server-cert.pem |
| 1363 |
&ssl_keyfile=%2Fvar%2Fssl%2Fprivate%2Fworker-key.pem' # /var/ssl/private/worker-key.pem |
| 1364 |
|
| 1365 |
Note that the ``ssl_cert_reqs`` string should be one of ``required``, |
| 1366 |
``optional``, or ``none`` (though, for backwards compatibility, the string |
| 1367 |
may also be one of ``CERT_REQUIRED``, ``CERT_OPTIONAL``, ``CERT_NONE``). |
| 1368 |
|
| 1369 |
|
| 1370 |
.. setting:: redis_backend_health_check_interval |
| 1371 |
|
| 1372 |
.. versionadded:: 5.1.0 |
| 1373 |
|
| 1374 |
``redis_backend_health_check_interval`` |
| 1375 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1376 |
|
| 1377 |
Default: Not configured |
| 1378 |
|
| 1379 |
The Redis backend supports health checks. This value must be |
| 1380 |
set as an integer whose value is the number of seconds between |
| 1381 |
health checks. If a ConnectionError or a TimeoutError is |
| 1382 |
encountered during the health check, the connection will be |
| 1383 |
re-established and the command retried exactly once. |
| 1384 |
|
| 1385 |
.. setting:: redis_backend_use_ssl |
| 1386 |
|
| 1387 |
``redis_backend_use_ssl`` |
| 1388 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1389 |
|
| 1390 |
Default: Disabled. |
| 1391 |
|
| 1392 |
The Redis backend supports SSL. This value must be set in |
| 1393 |
the form of a dictionary. The valid key-value pairs are |
| 1394 |
the same as the ones mentioned in the ``redis`` sub-section |
| 1395 |
under :setting:`broker_use_ssl`. |
| 1396 |
|
| 1397 |
.. setting:: redis_backend_credential_provider |
| 1398 |
|
| 1399 |
.. versionadded:: 5.6 |
| 1400 |
|
| 1401 |
``redis_backend_credential_provider`` |
| 1402 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1403 |
|
| 1404 |
Default: Disabled. |
| 1405 |
|
| 1406 |
The Redis backend supports credential provider. This value must be set in |
| 1407 |
the form of a class path string or a class instance. e.g. ``mymodule.myfile.myclass`` |
| 1408 |
check more details in `RedisCredentialProvider`_ doc. |
| 1409 |
|
| 1410 |
.. setting:: redis_max_connections |
| 1411 |
|
| 1412 |
``redis_max_connections`` |
| 1413 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1414 |
|
| 1415 |
Default: No limit. |
| 1416 |
|
| 1417 |
Maximum number of connections available in the Redis connection |
| 1418 |
pool used for sending and retrieving results. |
| 1419 |
|
| 1420 |
.. warning:: |
| 1421 |
Redis will raise a `ConnectionError` if the number of concurrent |
| 1422 |
connections exceeds the maximum. |
| 1423 |
|
| 1424 |
.. setting:: redis_socket_connect_timeout |
| 1425 |
|
| 1426 |
``redis_socket_connect_timeout`` |
| 1427 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1428 |
|
| 1429 |
.. versionadded:: 4.0.1 |
| 1430 |
|
| 1431 |
Default: :const:`None` |
| 1432 |
|
| 1433 |
Socket timeout for connections to Redis from the result backend |
| 1434 |
in seconds (int/float) |
| 1435 |
|
| 1436 |
.. setting:: redis_socket_timeout |
| 1437 |
|
| 1438 |
``redis_socket_timeout`` |
| 1439 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1440 |
|
| 1441 |
Default: 120.0 seconds. |
| 1442 |
|
| 1443 |
Socket timeout for reading/writing operations to the Redis server |
| 1444 |
in seconds (int/float), used by the redis result backend. |
| 1445 |
|
| 1446 |
.. setting:: redis_retry_on_timeout |
| 1447 |
|
| 1448 |
``redis_retry_on_timeout`` |
| 1449 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1450 |
|
| 1451 |
.. versionadded:: 4.4.1 |
| 1452 |
|
| 1453 |
Default: :const:`False` |
| 1454 |
|
| 1455 |
To retry reading/writing operations on TimeoutError to the Redis server, |
| 1456 |
used by the redis result backend. Shouldn't set this variable if using Redis |
| 1457 |
connection by unix socket. |
| 1458 |
|
| 1459 |
.. setting:: redis_socket_keepalive |
| 1460 |
|
| 1461 |
``redis_socket_keepalive`` |
| 1462 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1463 |
|
| 1464 |
.. versionadded:: 4.4.1 |
| 1465 |
|
| 1466 |
Default: :const:`False` |
| 1467 |
|
| 1468 |
Socket TCP keepalive to keep connections healthy to the Redis server, |
| 1469 |
used by the redis result backend. |
| 1470 |
|
| 1471 |
.. setting:: redis_client_name |
| 1472 |
|
| 1473 |
``redis_client_name`` |
| 1474 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1475 |
|
| 1476 |
.. versionadded:: 5.6 |
| 1477 |
|
| 1478 |
Default: :const:`None` |
| 1479 |
|
| 1480 |
Sets the client name for Redis connections used by the result backend. |
| 1481 |
This can help identify connections in Redis monitoring tools. |
| 1482 |
|
| 1483 |
.. _conf-cassandra-result-backend: |
| 1484 |
|
| 1485 |
Cassandra/AstraDB backend settings |
| 1486 |
---------------------------------- |
| 1487 |
|
| 1488 |
.. note:: |
| 1489 |
|
| 1490 |
This Cassandra backend driver requires :pypi:`cassandra-driver`. |
| 1491 |
|
| 1492 |
This backend can refer to either a regular Cassandra installation |
| 1493 |
or a managed Astra DB instance. Depending on which one, exactly one |
| 1494 |
between the :setting:`cassandra_servers` and |
| 1495 |
:setting:`cassandra_secure_bundle_path` settings must be provided |
| 1496 |
(but not both). |
| 1497 |
|
| 1498 |
To install, use :command:`pip`: |
| 1499 |
|
| 1500 |
.. code-block:: console |
| 1501 |
|
| 1502 |
$ pip install celery[cassandra] |
| 1503 |
|
| 1504 |
See :ref:`bundles` for information on combining multiple extension |
| 1505 |
requirements. |
| 1506 |
|
| 1507 |
This backend requires the following configuration directives to be set. |
| 1508 |
|
| 1509 |
.. setting:: cassandra_servers |
| 1510 |
|
| 1511 |
``cassandra_servers`` |
| 1512 |
~~~~~~~~~~~~~~~~~~~~~ |
| 1513 |
|
| 1514 |
Default: ``[]`` (empty list). |
| 1515 |
|
| 1516 |
List of ``host`` Cassandra servers. This must be provided when connecting to |
| 1517 |
a Cassandra cluster. Passing this setting is strictly exclusive |
| 1518 |
to :setting:`cassandra_secure_bundle_path`. Example:: |
| 1519 |
|
| 1520 |
cassandra_servers = ['localhost'] |
| 1521 |
|
| 1522 |
.. setting:: cassandra_secure_bundle_path |
| 1523 |
|
| 1524 |
``cassandra_secure_bundle_path`` |
| 1525 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1526 |
|
| 1527 |
Default: None. |
| 1528 |
|
| 1529 |
Absolute path to the secure-connect-bundle zip file to connect |
| 1530 |
to an Astra DB instance. Passing this setting is strictly exclusive |
| 1531 |
to :setting:`cassandra_servers`. |
| 1532 |
Example:: |
| 1533 |
|
| 1534 |
cassandra_secure_bundle_path = '/home/user/bundles/secure-connect.zip' |
| 1535 |
|
| 1536 |
When connecting to Astra DB, it is necessary to specify |
| 1537 |
the plain-text auth provider and the associated username and password, |
| 1538 |
which take the value of the Client ID and the Client Secret, respectively, |
| 1539 |
of a valid token generated for the Astra DB instance. |
| 1540 |
See below for an Astra DB configuration example. |
| 1541 |
|
| 1542 |
.. setting:: cassandra_port |
| 1543 |
|
| 1544 |
``cassandra_port`` |
| 1545 |
~~~~~~~~~~~~~~~~~~ |
| 1546 |
|
| 1547 |
Default: 9042. |
| 1548 |
|
| 1549 |
Port to contact the Cassandra servers on. |
| 1550 |
|
| 1551 |
.. setting:: cassandra_keyspace |
| 1552 |
|
| 1553 |
``cassandra_keyspace`` |
| 1554 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 1555 |
|
| 1556 |
Default: None. |
| 1557 |
|
| 1558 |
The keyspace in which to store the results. For example:: |
| 1559 |
|
| 1560 |
cassandra_keyspace = 'tasks_keyspace' |
| 1561 |
|
| 1562 |
.. setting:: cassandra_table |
| 1563 |
|
| 1564 |
``cassandra_table`` |
| 1565 |
~~~~~~~~~~~~~~~~~~~ |
| 1566 |
|
| 1567 |
Default: None. |
| 1568 |
|
| 1569 |
The table (column family) in which to store the results. For example:: |
| 1570 |
|
| 1571 |
cassandra_table = 'tasks' |
| 1572 |
|
| 1573 |
.. setting:: cassandra_read_consistency |
| 1574 |
|
| 1575 |
``cassandra_read_consistency`` |
| 1576 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1577 |
|
| 1578 |
Default: None. |
| 1579 |
|
| 1580 |
The read consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``, |
| 1581 |
``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``. |
| 1582 |
|
| 1583 |
.. setting:: cassandra_write_consistency |
| 1584 |
|
| 1585 |
``cassandra_write_consistency`` |
| 1586 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1587 |
|
| 1588 |
Default: None. |
| 1589 |
|
| 1590 |
The write consistency used. Values can be ``ONE``, ``TWO``, ``THREE``, ``QUORUM``, ``ALL``, |
| 1591 |
``LOCAL_QUORUM``, ``EACH_QUORUM``, ``LOCAL_ONE``. |
| 1592 |
|
| 1593 |
.. setting:: cassandra_entry_ttl |
| 1594 |
|
| 1595 |
``cassandra_entry_ttl`` |
| 1596 |
~~~~~~~~~~~~~~~~~~~~~~~ |
| 1597 |
|
| 1598 |
Default: None. |
| 1599 |
|
| 1600 |
Time-to-live for status entries. They will expire and be removed after that many seconds |
| 1601 |
after adding. A value of :const:`None` (default) means they will never expire. |
| 1602 |
|
| 1603 |
.. setting:: cassandra_auth_provider |
| 1604 |
|
| 1605 |
``cassandra_auth_provider`` |
| 1606 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1607 |
|
| 1608 |
Default: :const:`None`. |
| 1609 |
|
| 1610 |
AuthProvider class within ``cassandra.auth`` module to use. Values can be |
| 1611 |
``PlainTextAuthProvider`` or ``SaslAuthProvider``. |
| 1612 |
|
| 1613 |
.. setting:: cassandra_auth_kwargs |
| 1614 |
|
| 1615 |
``cassandra_auth_kwargs`` |
| 1616 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1617 |
|
| 1618 |
Default: ``{}`` (empty mapping). |
| 1619 |
|
| 1620 |
Named arguments to pass into the authentication provider. For example: |
| 1621 |
|
| 1622 |
.. code-block:: python |
| 1623 |
|
| 1624 |
cassandra_auth_kwargs = { |
| 1625 |
username: 'cassandra', |
| 1626 |
password: 'cassandra' |
| 1627 |
} |
| 1628 |
|
| 1629 |
.. setting:: cassandra_options |
| 1630 |
|
| 1631 |
``cassandra_options`` |
| 1632 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1633 |
|
| 1634 |
Default: ``{}`` (empty mapping). |
| 1635 |
|
| 1636 |
Named arguments to pass into the ``cassandra.cluster`` class. |
| 1637 |
|
| 1638 |
.. code-block:: python |
| 1639 |
|
| 1640 |
cassandra_options = { |
| 1641 |
'cql_version': '3.2.1' |
| 1642 |
'protocol_version': 3 |
| 1643 |
} |
| 1644 |
|
| 1645 |
Example configuration (Cassandra) |
| 1646 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1647 |
|
| 1648 |
.. code-block:: python |
| 1649 |
|
| 1650 |
result_backend = 'cassandra://' |
| 1651 |
cassandra_servers = ['localhost'] |
| 1652 |
cassandra_keyspace = 'celery' |
| 1653 |
cassandra_table = 'tasks' |
| 1654 |
cassandra_read_consistency = 'QUORUM' |
| 1655 |
cassandra_write_consistency = 'QUORUM' |
| 1656 |
cassandra_entry_ttl = 86400 |
| 1657 |
|
| 1658 |
Example configuration (Astra DB) |
| 1659 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1660 |
|
| 1661 |
.. code-block:: python |
| 1662 |
|
| 1663 |
result_backend = 'cassandra://' |
| 1664 |
cassandra_keyspace = 'celery' |
| 1665 |
cassandra_table = 'tasks' |
| 1666 |
cassandra_read_consistency = 'QUORUM' |
| 1667 |
cassandra_write_consistency = 'QUORUM' |
| 1668 |
cassandra_auth_provider = 'PlainTextAuthProvider' |
| 1669 |
cassandra_auth_kwargs = { |
| 1670 |
'username': '<<CLIENT_ID_FROM_ASTRA_DB_TOKEN>>', |
| 1671 |
'password': '<<CLIENT_SECRET_FROM_ASTRA_DB_TOKEN>>' |
| 1672 |
} |
| 1673 |
cassandra_secure_bundle_path = '/path/to/secure-connect-bundle.zip' |
| 1674 |
cassandra_entry_ttl = 86400 |
| 1675 |
|
| 1676 |
Additional configuration |
| 1677 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1678 |
|
| 1679 |
The Cassandra driver, when establishing the connection, undergoes a stage |
| 1680 |
of negotiating the protocol version with the server(s). Similarly, |
| 1681 |
a load-balancing policy is automatically supplied (by default |
| 1682 |
``DCAwareRoundRobinPolicy``, which in turn has a ``local_dc`` setting, also |
| 1683 |
determined by the driver upon connection). |
| 1684 |
When possible, one should explicitly provide these in the configuration: |
| 1685 |
moreover, future versions of the Cassandra driver will require at least the |
| 1686 |
load-balancing policy to be specified (using `execution profiles <https://docs.datastax.com/en/developer/python-driver/3.25/execution_profiles/>`_, |
| 1687 |
as shown below). |
| 1688 |
|
| 1689 |
A full configuration for the Cassandra backend would thus have the |
| 1690 |
following additional lines: |
| 1691 |
|
| 1692 |
.. code-block:: python |
| 1693 |
|
| 1694 |
from cassandra.policies import DCAwareRoundRobinPolicy |
| 1695 |
from cassandra.cluster import ExecutionProfile |
| 1696 |
from cassandra.cluster import EXEC_PROFILE_DEFAULT |
| 1697 |
myEProfile = ExecutionProfile( |
| 1698 |
load_balancing_policy=DCAwareRoundRobinPolicy( |
| 1699 |
local_dc='datacenter1', # replace with your DC name |
| 1700 |
) |
| 1701 |
) |
| 1702 |
cassandra_options = { |
| 1703 |
'protocol_version': 5, # for Cassandra 4, change if needed |
| 1704 |
'execution_profiles': {EXEC_PROFILE_DEFAULT: myEProfile}, |
| 1705 |
} |
| 1706 |
|
| 1707 |
And similarly for Astra DB: |
| 1708 |
|
| 1709 |
.. code-block:: python |
| 1710 |
|
| 1711 |
from cassandra.policies import DCAwareRoundRobinPolicy |
| 1712 |
from cassandra.cluster import ExecutionProfile |
| 1713 |
from cassandra.cluster import EXEC_PROFILE_DEFAULT |
| 1714 |
myEProfile = ExecutionProfile( |
| 1715 |
load_balancing_policy=DCAwareRoundRobinPolicy( |
| 1716 |
local_dc='europe-west1', # for Astra DB, region name = dc name |
| 1717 |
) |
| 1718 |
) |
| 1719 |
cassandra_options = { |
| 1720 |
'protocol_version': 4, # for Astra DB |
| 1721 |
'execution_profiles': {EXEC_PROFILE_DEFAULT: myEProfile}, |
| 1722 |
} |
| 1723 |
|
| 1724 |
.. _conf-s3-result-backend: |
| 1725 |
|
| 1726 |
S3 backend settings |
| 1727 |
------------------- |
| 1728 |
|
| 1729 |
.. note:: |
| 1730 |
|
| 1731 |
This s3 backend driver requires :pypi:`s3`. |
| 1732 |
|
| 1733 |
To install, use :command:`s3`: |
| 1734 |
|
| 1735 |
.. code-block:: console |
| 1736 |
|
| 1737 |
$ pip install celery[s3] |
| 1738 |
|
| 1739 |
See :ref:`bundles` for information on combining multiple extension |
| 1740 |
requirements. |
| 1741 |
|
| 1742 |
This backend requires the following configuration directives to be set. |
| 1743 |
|
| 1744 |
.. setting:: s3_access_key_id |
| 1745 |
|
| 1746 |
``s3_access_key_id`` |
| 1747 |
~~~~~~~~~~~~~~~~~~~~ |
| 1748 |
|
| 1749 |
Default: None. |
| 1750 |
|
| 1751 |
The s3 access key id. For example:: |
| 1752 |
|
| 1753 |
s3_access_key_id = 'access_key_id' |
| 1754 |
|
| 1755 |
.. setting:: s3_secret_access_key |
| 1756 |
|
| 1757 |
``s3_secret_access_key`` |
| 1758 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1759 |
|
| 1760 |
Default: None. |
| 1761 |
|
| 1762 |
The s3 secret access key. For example:: |
| 1763 |
|
| 1764 |
s3_secret_access_key = 'access_secret_access_key' |
| 1765 |
|
| 1766 |
.. setting:: s3_bucket |
| 1767 |
|
| 1768 |
``s3_bucket`` |
| 1769 |
~~~~~~~~~~~~~ |
| 1770 |
|
| 1771 |
Default: None. |
| 1772 |
|
| 1773 |
The s3 bucket name. For example:: |
| 1774 |
|
| 1775 |
s3_bucket = 'bucket_name' |
| 1776 |
|
| 1777 |
.. setting:: s3_base_path |
| 1778 |
|
| 1779 |
``s3_base_path`` |
| 1780 |
~~~~~~~~~~~~~~~~ |
| 1781 |
|
| 1782 |
Default: None. |
| 1783 |
|
| 1784 |
A base path in the s3 bucket to use to store result keys. For example:: |
| 1785 |
|
| 1786 |
s3_base_path = '/prefix' |
| 1787 |
|
| 1788 |
.. setting:: s3_endpoint_url |
| 1789 |
|
| 1790 |
``s3_endpoint_url`` |
| 1791 |
~~~~~~~~~~~~~~~~~~~ |
| 1792 |
|
| 1793 |
Default: None. |
| 1794 |
|
| 1795 |
A custom s3 endpoint url. Use it to connect to a custom self-hosted s3 compatible backend (Ceph, Scality...). For example:: |
| 1796 |
|
| 1797 |
s3_endpoint_url = 'https://.s3.custom.url' |
| 1798 |
|
| 1799 |
.. setting:: s3_region |
| 1800 |
|
| 1801 |
``s3_region`` |
| 1802 |
~~~~~~~~~~~~~ |
| 1803 |
|
| 1804 |
Default: None. |
| 1805 |
|
| 1806 |
The s3 aws region. For example:: |
| 1807 |
|
| 1808 |
s3_region = 'us-east-1' |
| 1809 |
|
| 1810 |
Example configuration |
| 1811 |
~~~~~~~~~~~~~~~~~~~~~ |
| 1812 |
|
| 1813 |
.. code-block:: python |
| 1814 |
|
| 1815 |
s3_access_key_id = 's3-access-key-id' |
| 1816 |
s3_secret_access_key = 's3-secret-access-key' |
| 1817 |
s3_bucket = 'mybucket' |
| 1818 |
s3_base_path = '/celery_result_backend' |
| 1819 |
s3_endpoint_url = 'https://endpoint_url' |
| 1820 |
|
| 1821 |
.. _conf-azureblockblob-result-backend: |
| 1822 |
|
| 1823 |
Azure Block Blob backend settings |
| 1824 |
--------------------------------- |
| 1825 |
|
| 1826 |
To use `AzureBlockBlob`_ as the result backend you simply need to |
| 1827 |
configure the :setting:`result_backend` setting with the correct URL. |
| 1828 |
|
| 1829 |
The required URL format is ``azureblockblob://`` followed by the storage |
| 1830 |
connection string. You can find the storage connection string in the |
| 1831 |
``Access Keys`` pane of your storage account resource in the Azure Portal. |
| 1832 |
|
| 1833 |
Example configuration |
| 1834 |
~~~~~~~~~~~~~~~~~~~~~ |
| 1835 |
|
| 1836 |
.. code-block:: python |
| 1837 |
|
| 1838 |
result_backend = 'azureblockblob://DefaultEndpointsProtocol=https;AccountName=somename;AccountKey=Lou...bzg==;EndpointSuffix=core.windows.net' |
| 1839 |
|
| 1840 |
.. setting:: azureblockblob_container_name |
| 1841 |
|
| 1842 |
``azureblockblob_container_name`` |
| 1843 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1844 |
|
| 1845 |
Default: celery. |
| 1846 |
|
| 1847 |
The name for the storage container in which to store the results. |
| 1848 |
|
| 1849 |
.. setting:: azureblockblob_base_path |
| 1850 |
|
| 1851 |
``azureblockblob_base_path`` |
| 1852 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1853 |
|
| 1854 |
.. versionadded:: 5.1 |
| 1855 |
|
| 1856 |
Default: None. |
| 1857 |
|
| 1858 |
A base path in the storage container to use to store result keys. For example:: |
| 1859 |
|
| 1860 |
azureblockblob_base_path = 'prefix/' |
| 1861 |
|
| 1862 |
.. setting:: azureblockblob_retry_initial_backoff_sec |
| 1863 |
|
| 1864 |
``azureblockblob_retry_initial_backoff_sec`` |
| 1865 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1866 |
|
| 1867 |
Default: 2. |
| 1868 |
|
| 1869 |
The initial backoff interval, in seconds, for the first retry. |
| 1870 |
Subsequent retries are attempted with an exponential strategy. |
| 1871 |
|
| 1872 |
.. setting:: azureblockblob_retry_increment_base |
| 1873 |
|
| 1874 |
``azureblockblob_retry_increment_base`` |
| 1875 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1876 |
|
| 1877 |
Default: 2. |
| 1878 |
|
| 1879 |
.. setting:: azureblockblob_retry_max_attempts |
| 1880 |
|
| 1881 |
``azureblockblob_retry_max_attempts`` |
| 1882 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1883 |
|
| 1884 |
Default: 3. |
| 1885 |
|
| 1886 |
The maximum number of retry attempts. |
| 1887 |
|
| 1888 |
.. setting:: azureblockblob_connection_timeout |
| 1889 |
|
| 1890 |
``azureblockblob_connection_timeout`` |
| 1891 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1892 |
|
| 1893 |
Default: 20. |
| 1894 |
|
| 1895 |
Timeout in seconds for establishing the azure block blob connection. |
| 1896 |
|
| 1897 |
.. setting:: azureblockblob_read_timeout |
| 1898 |
|
| 1899 |
``azureblockblob_read_timeout`` |
| 1900 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1901 |
|
| 1902 |
Default: 120. |
| 1903 |
|
| 1904 |
Timeout in seconds for reading of an azure block blob. |
| 1905 |
|
| 1906 |
.. _conf-gcs-result-backend: |
| 1907 |
|
| 1908 |
GCS backend settings |
| 1909 |
-------------------- |
| 1910 |
|
| 1911 |
.. note:: |
| 1912 |
|
| 1913 |
This gcs backend driver requires :pypi:`google-cloud-storage` and :pypi:`google-cloud-firestore`. |
| 1914 |
|
| 1915 |
To install, use :command:`gcs`: |
| 1916 |
|
| 1917 |
.. code-block:: console |
| 1918 |
|
| 1919 |
$ pip install celery[gcs] |
| 1920 |
|
| 1921 |
See :ref:`bundles` for information on combining multiple extension |
| 1922 |
requirements. |
| 1923 |
|
| 1924 |
GCS could be configured via the URL provided in :setting:`result_backend`, for example:: |
| 1925 |
|
| 1926 |
result_backend = 'gs://mybucket/some-prefix?gcs_project=myproject&ttl=600' |
| 1927 |
result_backend = 'gs://mybucket/some-prefix?gcs_project=myproject?firestore_project=myproject2&ttl=600' |
| 1928 |
|
| 1929 |
This backend requires the following configuration directives to be set: |
| 1930 |
|
| 1931 |
.. setting:: gcs_bucket |
| 1932 |
|
| 1933 |
``gcs_bucket`` |
| 1934 |
~~~~~~~~~~~~~~ |
| 1935 |
|
| 1936 |
Default: None. |
| 1937 |
|
| 1938 |
The gcs bucket name. For example:: |
| 1939 |
|
| 1940 |
gcs_bucket = 'bucket_name' |
| 1941 |
|
| 1942 |
.. setting:: gcs_project |
| 1943 |
|
| 1944 |
``gcs_project`` |
| 1945 |
~~~~~~~~~~~~~~~ |
| 1946 |
|
| 1947 |
Default: None. |
| 1948 |
|
| 1949 |
The gcs project name. For example:: |
| 1950 |
|
| 1951 |
gcs_project = 'test-project' |
| 1952 |
|
| 1953 |
.. setting:: gcs_base_path |
| 1954 |
|
| 1955 |
``gcs_base_path`` |
| 1956 |
~~~~~~~~~~~~~~~~~ |
| 1957 |
|
| 1958 |
Default: None. |
| 1959 |
|
| 1960 |
A base path in the gcs bucket to use to store all result keys. For example:: |
| 1961 |
|
| 1962 |
gcs_base_path = '/prefix' |
| 1963 |
|
| 1964 |
``gcs_ttl`` |
| 1965 |
~~~~~~~~~~~ |
| 1966 |
|
| 1967 |
Default: 0. |
| 1968 |
|
| 1969 |
The time to live in seconds for the results blobs. |
| 1970 |
Requires a GCS bucket with "Delete" Object Lifecycle Management action enabled. |
| 1971 |
Use it to automatically delete results from Cloud Storage Buckets. |
| 1972 |
|
| 1973 |
For example to auto remove results after 24 hours:: |
| 1974 |
|
| 1975 |
gcs_ttl = 86400 |
| 1976 |
|
| 1977 |
``gcs_threadpool_maxsize`` |
| 1978 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1979 |
|
| 1980 |
Default: 10. |
| 1981 |
|
| 1982 |
Threadpool size for GCS operations. Same value defines the connection pool size. |
| 1983 |
Allows to control the number of concurrent operations. For example:: |
| 1984 |
|
| 1985 |
gcs_threadpool_maxsize = 20 |
| 1986 |
|
| 1987 |
``firestore_project`` |
| 1988 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1989 |
|
| 1990 |
Default: gcs_project. |
| 1991 |
|
| 1992 |
The Firestore project for Chord reference counting. Allows native chord ref counts. |
| 1993 |
If not specified defaults to :setting:`gcs_project`. |
| 1994 |
For example:: |
| 1995 |
|
| 1996 |
firestore_project = 'test-project2' |
| 1997 |
|
| 1998 |
Example configuration |
| 1999 |
~~~~~~~~~~~~~~~~~~~~~ |
| 2000 |
|
| 2001 |
.. code-block:: python |
| 2002 |
|
| 2003 |
gcs_bucket = 'mybucket' |
| 2004 |
gcs_project = 'myproject' |
| 2005 |
gcs_base_path = '/celery_result_backend' |
| 2006 |
gcs_ttl = 86400 |
| 2007 |
|
| 2008 |
.. _conf-elasticsearch-result-backend: |
| 2009 |
|
| 2010 |
Elasticsearch backend settings |
| 2011 |
------------------------------ |
| 2012 |
|
| 2013 |
To use `Elasticsearch`_ as the result backend you simply need to |
| 2014 |
configure the :setting:`result_backend` setting with the correct URL. |
| 2015 |
|
| 2016 |
Example configuration |
| 2017 |
~~~~~~~~~~~~~~~~~~~~~ |
| 2018 |
|
| 2019 |
.. code-block:: python |
| 2020 |
|
| 2021 |
result_backend = 'elasticsearch://example.com:9200/index_name/doc_type' |
| 2022 |
|
| 2023 |
.. setting:: elasticsearch_retry_on_timeout |
| 2024 |
|
| 2025 |
``elasticsearch_retry_on_timeout`` |
| 2026 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2027 |
|
| 2028 |
Default: :const:`False` |
| 2029 |
|
| 2030 |
Should timeout trigger a retry on different node? |
| 2031 |
|
| 2032 |
.. setting:: elasticsearch_max_retries |
| 2033 |
|
| 2034 |
``elasticsearch_max_retries`` |
| 2035 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2036 |
|
| 2037 |
Default: 3. |
| 2038 |
|
| 2039 |
Maximum number of retries before an exception is propagated. |
| 2040 |
|
| 2041 |
.. setting:: elasticsearch_timeout |
| 2042 |
|
| 2043 |
``elasticsearch_timeout`` |
| 2044 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2045 |
|
| 2046 |
Default: 10.0 seconds. |
| 2047 |
|
| 2048 |
Global timeout,used by the elasticsearch result backend. |
| 2049 |
|
| 2050 |
.. setting:: elasticsearch_save_meta_as_text |
| 2051 |
|
| 2052 |
``elasticsearch_save_meta_as_text`` |
| 2053 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2054 |
|
| 2055 |
Default: :const:`True` |
| 2056 |
|
| 2057 |
Should meta saved as text or as native json. |
| 2058 |
Result is always serialized as text. |
| 2059 |
|
| 2060 |
.. _conf-dynamodb-result-backend: |
| 2061 |
|
| 2062 |
AWS DynamoDB backend settings |
| 2063 |
----------------------------- |
| 2064 |
|
| 2065 |
.. note:: |
| 2066 |
|
| 2067 |
The Dynamodb backend requires the :pypi:`boto3` library. |
| 2068 |
|
| 2069 |
To install this package use :command:`pip`: |
| 2070 |
|
| 2071 |
.. code-block:: console |
| 2072 |
|
| 2073 |
$ pip install celery[dynamodb] |
| 2074 |
|
| 2075 |
See :ref:`bundles` for information on combining multiple extension |
| 2076 |
requirements. |
| 2077 |
|
| 2078 |
.. warning:: |
| 2079 |
|
| 2080 |
The Dynamodb backend is not compatible with tables that have a sort key defined. |
| 2081 |
|
| 2082 |
If you want to query the results table based on something other than the partition key, |
| 2083 |
please define a global secondary index (GSI) instead. |
| 2084 |
|
| 2085 |
This backend requires the :setting:`result_backend` |
| 2086 |
setting to be set to a DynamoDB URL:: |
| 2087 |
|
| 2088 |
result_backend = 'dynamodb://aws_access_key_id:aws_secret_access_key@region:port/table?read=n&write=m' |
| 2089 |
|
| 2090 |
For example, specifying the AWS region and the table name:: |
| 2091 |
|
| 2092 |
result_backend = 'dynamodb://@us-east-1/celery_results' |
| 2093 |
|
| 2094 |
or retrieving AWS configuration parameters from the environment, using the default table name (``celery``) |
| 2095 |
and specifying read and write provisioned throughput:: |
| 2096 |
|
| 2097 |
result_backend = 'dynamodb://@/?read=5&write=5' |
| 2098 |
|
| 2099 |
or using the `downloadable version <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html>`_ |
| 2100 |
of DynamoDB |
| 2101 |
`locally <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.Endpoint.html>`_:: |
| 2102 |
|
| 2103 |
result_backend = 'dynamodb://@localhost:8000' |
| 2104 |
|
| 2105 |
or using downloadable version or other service with conforming API deployed on any host:: |
| 2106 |
|
| 2107 |
result_backend = 'dynamodb://@us-east-1' |
| 2108 |
dynamodb_endpoint_url = 'http://192.168.0.40:8000' |
| 2109 |
|
| 2110 |
The fields of the DynamoDB URL in ``result_backend`` are defined as follows: |
| 2111 |
|
| 2112 |
#. ``aws_access_key_id & aws_secret_access_key`` |
| 2113 |
|
| 2114 |
The credentials for accessing AWS API resources. These can also be resolved |
| 2115 |
by the :pypi:`boto3` library from various sources, as |
| 2116 |
described `here <http://boto3.readthedocs.io/en/latest/guide/configuration.html#configuring-credentials>`_. |
| 2117 |
|
| 2118 |
#. ``region`` |
| 2119 |
|
| 2120 |
The AWS region, e.g. ``us-east-1`` or ``localhost`` for the `Downloadable Version <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html>`_. |
| 2121 |
See the :pypi:`boto3` library `documentation <http://boto3.readthedocs.io/en/latest/guide/configuration.html#environment-variable-configuration>`_ |
| 2122 |
for definition options. |
| 2123 |
|
| 2124 |
#. ``port`` |
| 2125 |
|
| 2126 |
The listening port of the local DynamoDB instance, if you are using the downloadable version. |
| 2127 |
If you have not specified the ``region`` parameter as ``localhost``, |
| 2128 |
setting this parameter has **no effect**. |
| 2129 |
|
| 2130 |
#. ``table`` |
| 2131 |
|
| 2132 |
Table name to use. Default is ``celery``. |
| 2133 |
See the `DynamoDB Naming Rules <http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-naming-rules>`_ |
| 2134 |
for information on the allowed characters and length. |
| 2135 |
|
| 2136 |
#. ``read & write`` |
| 2137 |
|
| 2138 |
The Read & Write Capacity Units for the created DynamoDB table. Default is ``1`` for both read and write. |
| 2139 |
More details can be found in the `Provisioned Throughput documentation <http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ProvisionedThroughput.html>`_. |
| 2140 |
|
| 2141 |
#. ``ttl_seconds`` |
| 2142 |
|
| 2143 |
Time-to-live (in seconds) for results before they expire. The default is to |
| 2144 |
not expire results, while also leaving the DynamoDB table's Time to Live |
| 2145 |
settings untouched. If ``ttl_seconds`` is set to a positive value, results |
| 2146 |
will expire after the specified number of seconds. Setting ``ttl_seconds`` |
| 2147 |
to a negative value means to not expire results, and also to actively |
| 2148 |
disable the DynamoDB table's Time to Live setting. Note that trying to |
| 2149 |
change a table's Time to Live setting multiple times in quick succession |
| 2150 |
will cause a throttling error. More details can be found in the |
| 2151 |
`DynamoDB TTL documentation <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html>`_ |
| 2152 |
|
| 2153 |
.. _conf-ironcache-result-backend: |
| 2154 |
|
| 2155 |
IronCache backend settings |
| 2156 |
-------------------------- |
| 2157 |
|
| 2158 |
.. note:: |
| 2159 |
|
| 2160 |
The IronCache backend requires the :pypi:`iron_celery` library: |
| 2161 |
|
| 2162 |
To install this package use :command:`pip`: |
| 2163 |
|
| 2164 |
.. code-block:: console |
| 2165 |
|
| 2166 |
$ pip install iron_celery |
| 2167 |
|
| 2168 |
IronCache is configured via the URL provided in :setting:`result_backend`, for example:: |
| 2169 |
|
| 2170 |
result_backend = 'ironcache://project_id:token@' |
| 2171 |
|
| 2172 |
Or to change the cache name:: |
| 2173 |
|
| 2174 |
ironcache:://project_id:token@/awesomecache |
| 2175 |
|
| 2176 |
For more information, see: https://github.com/iron-io/iron_celery |
| 2177 |
|
| 2178 |
.. _conf-couchbase-result-backend: |
| 2179 |
|
| 2180 |
Couchbase backend settings |
| 2181 |
-------------------------- |
| 2182 |
|
| 2183 |
.. note:: |
| 2184 |
|
| 2185 |
The Couchbase backend requires the :pypi:`couchbase` library. |
| 2186 |
|
| 2187 |
To install this package use :command:`pip`: |
| 2188 |
|
| 2189 |
.. code-block:: console |
| 2190 |
|
| 2191 |
$ pip install celery[couchbase] |
| 2192 |
|
| 2193 |
See :ref:`bundles` for instructions how to combine multiple extension |
| 2194 |
requirements. |
| 2195 |
|
| 2196 |
This backend can be configured via the :setting:`result_backend` |
| 2197 |
set to a Couchbase URL: |
| 2198 |
|
| 2199 |
.. code-block:: python |
| 2200 |
|
| 2201 |
result_backend = 'couchbase://username:password@host:port/bucket' |
| 2202 |
|
| 2203 |
.. setting:: couchbase_backend_settings |
| 2204 |
|
| 2205 |
``couchbase_backend_settings`` |
| 2206 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2207 |
|
| 2208 |
Default: ``{}`` (empty mapping). |
| 2209 |
|
| 2210 |
This is a dict supporting the following keys: |
| 2211 |
|
| 2212 |
* ``host`` |
| 2213 |
|
| 2214 |
Host name of the Couchbase server. Defaults to ``localhost``. |
| 2215 |
|
| 2216 |
* ``port`` |
| 2217 |
|
| 2218 |
The port the Couchbase server is listening to. Defaults to ``8091``. |
| 2219 |
|
| 2220 |
* ``bucket`` |
| 2221 |
|
| 2222 |
The default bucket the Couchbase server is writing to. |
| 2223 |
Defaults to ``default``. |
| 2224 |
|
| 2225 |
* ``username`` |
| 2226 |
|
| 2227 |
User name to authenticate to the Couchbase server as (optional). |
| 2228 |
|
| 2229 |
* ``password`` |
| 2230 |
|
| 2231 |
Password to authenticate to the Couchbase server (optional). |
| 2232 |
|
| 2233 |
.. _conf-arangodb-result-backend: |
| 2234 |
|
| 2235 |
ArangoDB backend settings |
| 2236 |
-------------------------- |
| 2237 |
|
| 2238 |
.. note:: |
| 2239 |
|
| 2240 |
The ArangoDB backend requires the :pypi:`pyArango` library. |
| 2241 |
|
| 2242 |
To install this package use :command:`pip`: |
| 2243 |
|
| 2244 |
.. code-block:: console |
| 2245 |
|
| 2246 |
$ pip install celery[arangodb] |
| 2247 |
|
| 2248 |
See :ref:`bundles` for instructions how to combine multiple extension |
| 2249 |
requirements. |
| 2250 |
|
| 2251 |
This backend can be configured via the :setting:`result_backend` |
| 2252 |
set to a ArangoDB URL: |
| 2253 |
|
| 2254 |
.. code-block:: python |
| 2255 |
|
| 2256 |
result_backend = 'arangodb://username:password@host:port/database/collection' |
| 2257 |
|
| 2258 |
.. setting:: arangodb_backend_settings |
| 2259 |
|
| 2260 |
``arangodb_backend_settings`` |
| 2261 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2262 |
|
| 2263 |
Default: ``{}`` (empty mapping). |
| 2264 |
|
| 2265 |
This is a dict supporting the following keys: |
| 2266 |
|
| 2267 |
* ``host`` |
| 2268 |
|
| 2269 |
Host name of the ArangoDB server. Defaults to ``localhost``. |
| 2270 |
|
| 2271 |
* ``port`` |
| 2272 |
|
| 2273 |
The port the ArangoDB server is listening to. Defaults to ``8529``. |
| 2274 |
|
| 2275 |
* ``database`` |
| 2276 |
|
| 2277 |
The default database in the ArangoDB server is writing to. |
| 2278 |
Defaults to ``celery``. |
| 2279 |
|
| 2280 |
* ``collection`` |
| 2281 |
|
| 2282 |
The default collection in the ArangoDB servers database is writing to. |
| 2283 |
Defaults to ``celery``. |
| 2284 |
|
| 2285 |
* ``username`` |
| 2286 |
|
| 2287 |
User name to authenticate to the ArangoDB server as (optional). |
| 2288 |
|
| 2289 |
* ``password`` |
| 2290 |
|
| 2291 |
Password to authenticate to the ArangoDB server (optional). |
| 2292 |
|
| 2293 |
* ``http_protocol`` |
| 2294 |
|
| 2295 |
HTTP Protocol in ArangoDB server connection. |
| 2296 |
Defaults to ``http``. |
| 2297 |
|
| 2298 |
* ``verify`` |
| 2299 |
|
| 2300 |
HTTPS Verification check while creating the ArangoDB connection. |
| 2301 |
Defaults to ``False``. |
| 2302 |
|
| 2303 |
.. _conf-cosmosdbsql-result-backend: |
| 2304 |
|
| 2305 |
CosmosDB backend settings (experimental) |
| 2306 |
---------------------------------------- |
| 2307 |
|
| 2308 |
To use `CosmosDB`_ as the result backend, you simply need to configure the |
| 2309 |
:setting:`result_backend` setting with the correct URL. |
| 2310 |
|
| 2311 |
Example configuration |
| 2312 |
~~~~~~~~~~~~~~~~~~~~~ |
| 2313 |
|
| 2314 |
.. code-block:: python |
| 2315 |
|
| 2316 |
result_backend = 'cosmosdbsql://:{InsertAccountPrimaryKeyHere}@{InsertAccountNameHere}.documents.azure.com' |
| 2317 |
|
| 2318 |
.. setting:: cosmosdbsql_database_name |
| 2319 |
|
| 2320 |
``cosmosdbsql_database_name`` |
| 2321 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2322 |
|
| 2323 |
Default: celerydb. |
| 2324 |
|
| 2325 |
The name for the database in which to store the results. |
| 2326 |
|
| 2327 |
.. setting:: cosmosdbsql_collection_name |
| 2328 |
|
| 2329 |
``cosmosdbsql_collection_name`` |
| 2330 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2331 |
|
| 2332 |
Default: celerycol. |
| 2333 |
|
| 2334 |
The name of the collection in which to store the results. |
| 2335 |
|
| 2336 |
.. setting:: cosmosdbsql_consistency_level |
| 2337 |
|
| 2338 |
``cosmosdbsql_consistency_level`` |
| 2339 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2340 |
|
| 2341 |
Default: Session. |
| 2342 |
|
| 2343 |
Represents the consistency levels supported for Azure Cosmos DB client operations. |
| 2344 |
|
| 2345 |
Consistency levels by order of strength are: Strong, BoundedStaleness, Session, ConsistentPrefix and Eventual. |
| 2346 |
|
| 2347 |
.. setting:: cosmosdbsql_max_retry_attempts |
| 2348 |
|
| 2349 |
``cosmosdbsql_max_retry_attempts`` |
| 2350 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2351 |
|
| 2352 |
Default: 9. |
| 2353 |
|
| 2354 |
Maximum number of retries to be performed for a request. |
| 2355 |
|
| 2356 |
.. setting:: cosmosdbsql_max_retry_wait_time |
| 2357 |
|
| 2358 |
``cosmosdbsql_max_retry_wait_time`` |
| 2359 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2360 |
|
| 2361 |
Default: 30. |
| 2362 |
|
| 2363 |
Maximum wait time in seconds to wait for a request while the retries are happening. |
| 2364 |
|
| 2365 |
.. _conf-couchdb-result-backend: |
| 2366 |
|
| 2367 |
CouchDB backend settings |
| 2368 |
------------------------ |
| 2369 |
|
| 2370 |
.. note:: |
| 2371 |
|
| 2372 |
The CouchDB backend requires the :pypi:`pycouchdb` library: |
| 2373 |
|
| 2374 |
To install this Couchbase package use :command:`pip`: |
| 2375 |
|
| 2376 |
.. code-block:: console |
| 2377 |
|
| 2378 |
$ pip install celery[couchdb] |
| 2379 |
|
| 2380 |
See :ref:`bundles` for information on combining multiple extension |
| 2381 |
requirements. |
| 2382 |
|
| 2383 |
This backend can be configured via the :setting:`result_backend` |
| 2384 |
set to a CouchDB URL:: |
| 2385 |
|
| 2386 |
result_backend = 'couchdb://username:password@host:port/container' |
| 2387 |
|
| 2388 |
The URL is formed out of the following parts: |
| 2389 |
|
| 2390 |
* ``username`` |
| 2391 |
|
| 2392 |
User name to authenticate to the CouchDB server as (optional). |
| 2393 |
|
| 2394 |
* ``password`` |
| 2395 |
|
| 2396 |
Password to authenticate to the CouchDB server (optional). |
| 2397 |
|
| 2398 |
* ``host`` |
| 2399 |
|
| 2400 |
Host name of the CouchDB server. Defaults to ``localhost``. |
| 2401 |
|
| 2402 |
* ``port`` |
| 2403 |
|
| 2404 |
The port the CouchDB server is listening to. Defaults to ``8091``. |
| 2405 |
|
| 2406 |
* ``container`` |
| 2407 |
|
| 2408 |
The default container the CouchDB server is writing to. |
| 2409 |
Defaults to ``default``. |
| 2410 |
|
| 2411 |
.. _conf-filesystem-result-backend: |
| 2412 |
|
| 2413 |
File-system backend settings |
| 2414 |
---------------------------- |
| 2415 |
|
| 2416 |
This backend can be configured using a file URL, for example:: |
| 2417 |
|
| 2418 |
CELERY_RESULT_BACKEND = 'file:///var/celery/results' |
| 2419 |
|
| 2420 |
The configured directory needs to be shared and writable by all servers using |
| 2421 |
the backend. |
| 2422 |
|
| 2423 |
If you're trying Celery on a single system you can simply use the backend |
| 2424 |
without any further configuration. For larger clusters you could use NFS, |
| 2425 |
`GlusterFS`_, CIFS, `HDFS`_ (using FUSE), or any other file-system. |
| 2426 |
|
| 2427 |
.. _`GlusterFS`: http://www.gluster.org/ |
| 2428 |
.. _`HDFS`: http://hadoop.apache.org/ |
| 2429 |
|
| 2430 |
.. _conf-consul-result-backend: |
| 2431 |
|
| 2432 |
Consul K/V store backend settings |
| 2433 |
--------------------------------- |
| 2434 |
|
| 2435 |
.. note:: |
| 2436 |
|
| 2437 |
The Consul backend requires the :pypi:`python-consul2` library: |
| 2438 |
|
| 2439 |
To install this package use :command:`pip`: |
| 2440 |
|
| 2441 |
.. code-block:: console |
| 2442 |
|
| 2443 |
$ pip install python-consul2 |
| 2444 |
|
| 2445 |
The Consul backend can be configured using a URL, for example:: |
| 2446 |
|
| 2447 |
CELERY_RESULT_BACKEND = 'consul://localhost:8500/' |
| 2448 |
|
| 2449 |
or:: |
| 2450 |
|
| 2451 |
result_backend = 'consul://localhost:8500/' |
| 2452 |
|
| 2453 |
The backend will store results in the K/V store of Consul |
| 2454 |
as individual keys. The backend supports auto expire of results using TTLs in |
| 2455 |
Consul. The full syntax of the URL is: |
| 2456 |
|
| 2457 |
.. code-block:: text |
| 2458 |
|
| 2459 |
consul://host:port[?one_client=1] |
| 2460 |
|
| 2461 |
The URL is formed out of the following parts: |
| 2462 |
|
| 2463 |
* ``host`` |
| 2464 |
|
| 2465 |
Host name of the Consul server. |
| 2466 |
|
| 2467 |
* ``port`` |
| 2468 |
|
| 2469 |
The port the Consul server is listening to. |
| 2470 |
|
| 2471 |
* ``one_client`` |
| 2472 |
|
| 2473 |
By default, for correctness, the backend uses a separate client connection |
| 2474 |
per operation. In cases of extreme load, the rate of creation of new |
| 2475 |
connections can cause HTTP 429 "too many connections" error responses from |
| 2476 |
the Consul server when under load. The recommended way to handle this is to |
| 2477 |
enable retries in ``python-consul2`` using the patch at |
| 2478 |
https://github.com/poppyred/python-consul2/pull/31. |
| 2479 |
|
| 2480 |
Alternatively, if ``one_client`` is set, a single client connection will be |
| 2481 |
used for all operations instead. This should eliminate the HTTP 429 errors, |
| 2482 |
but the storage of results in the backend can become unreliable. |
| 2483 |
|
| 2484 |
.. _conf-messaging: |
| 2485 |
|
| 2486 |
Message Routing |
| 2487 |
--------------- |
| 2488 |
|
| 2489 |
.. _conf-messaging-routing: |
| 2490 |
|
| 2491 |
.. setting:: task_queues |
| 2492 |
|
| 2493 |
``task_queues`` |
| 2494 |
~~~~~~~~~~~~~~~ |
| 2495 |
|
| 2496 |
Default: :const:`None` (queue taken from default queue settings). |
| 2497 |
|
| 2498 |
Most users will not want to specify this setting and should rather use |
| 2499 |
the :ref:`automatic routing facilities <routing-automatic>`. |
| 2500 |
|
| 2501 |
If you really want to configure advanced routing, this setting should |
| 2502 |
be a list of :class:`kombu.Queue` objects the worker will consume from. |
| 2503 |
|
| 2504 |
Note that workers can be overridden this setting via the |
| 2505 |
:option:`-Q <celery worker -Q>` option, or individual queues from this |
| 2506 |
list (by name) can be excluded using the :option:`-X <celery worker -X>` |
| 2507 |
option. |
| 2508 |
|
| 2509 |
Also see :ref:`routing-basics` for more information. |
| 2510 |
|
| 2511 |
The default is a queue/exchange/binding key of ``celery``, with |
| 2512 |
exchange type ``direct``. |
| 2513 |
|
| 2514 |
See also :setting:`task_routes` |
| 2515 |
|
| 2516 |
.. setting:: task_routes |
| 2517 |
|
| 2518 |
``task_routes`` |
| 2519 |
~~~~~~~~~~~~~~~ |
| 2520 |
|
| 2521 |
Default: :const:`None`. |
| 2522 |
|
| 2523 |
A list of routers, or a single router used to route tasks to queues. |
| 2524 |
When deciding the final destination of a task the routers are consulted |
| 2525 |
in order. |
| 2526 |
|
| 2527 |
A router can be specified as either: |
| 2528 |
|
| 2529 |
* A function with the signature ``(name, args, kwargs, |
| 2530 |
options, task=None, **kwargs)`` |
| 2531 |
* A string providing the path to a router function. |
| 2532 |
* A dict containing router specification: |
| 2533 |
Will be converted to a :class:`celery.routes.MapRoute` instance. |
| 2534 |
* A list of ``(pattern, route)`` tuples: |
| 2535 |
Will be converted to a :class:`celery.routes.MapRoute` instance. |
| 2536 |
|
| 2537 |
Examples: |
| 2538 |
|
| 2539 |
.. code-block:: python |
| 2540 |
|
| 2541 |
task_routes = { |
| 2542 |
'celery.ping': 'default', |
| 2543 |
'mytasks.add': 'cpu-bound', |
| 2544 |
'feed.tasks.*': 'feeds', # <-- glob pattern |
| 2545 |
re.compile(r'(image|video)\.tasks\..*'): 'media', # <-- regex |
| 2546 |
'video.encode': { |
| 2547 |
'queue': 'video', |
| 2548 |
'exchange': 'media', |
| 2549 |
'routing_key': 'media.video.encode', |
| 2550 |
}, |
| 2551 |
} |
| 2552 |
|
| 2553 |
task_routes = ('myapp.tasks.route_task', {'celery.ping': 'default'}) |
| 2554 |
|
| 2555 |
Where ``myapp.tasks.route_task`` could be: |
| 2556 |
|
| 2557 |
.. code-block:: python |
| 2558 |
|
| 2559 |
def route_task(self, name, args, kwargs, options, task=None, **kw): |
| 2560 |
if task == 'celery.ping': |
| 2561 |
return {'queue': 'default'} |
| 2562 |
|
| 2563 |
``route_task`` may return a string or a dict. A string then means |
| 2564 |
it's a queue name in :setting:`task_queues`, a dict means it's a custom route. |
| 2565 |
|
| 2566 |
When sending tasks, the routers are consulted in order. The first |
| 2567 |
router that doesn't return ``None`` is the route to use. The message options |
| 2568 |
is then merged with the found route settings, where the task's settings |
| 2569 |
have priority. |
| 2570 |
|
| 2571 |
Example if :func:`~celery.execute.apply_async` has these arguments: |
| 2572 |
|
| 2573 |
.. code-block:: python |
| 2574 |
|
| 2575 |
Task.apply_async(immediate=False, exchange='video', |
| 2576 |
routing_key='video.compress') |
| 2577 |
|
| 2578 |
and a router returns: |
| 2579 |
|
| 2580 |
.. code-block:: python |
| 2581 |
|
| 2582 |
{'immediate': True, 'exchange': 'urgent'} |
| 2583 |
|
| 2584 |
the final message options will be: |
| 2585 |
|
| 2586 |
.. code-block:: python |
| 2587 |
|
| 2588 |
immediate=False, exchange='video', routing_key='video.compress' |
| 2589 |
|
| 2590 |
(and any default message options defined in the |
| 2591 |
:class:`~celery.app.task.Task` class) |
| 2592 |
|
| 2593 |
Values defined in :setting:`task_routes` have precedence over values defined in |
| 2594 |
:setting:`task_queues` when merging the two. |
| 2595 |
|
| 2596 |
With the follow settings: |
| 2597 |
|
| 2598 |
.. code-block:: python |
| 2599 |
|
| 2600 |
task_queues = { |
| 2601 |
'cpubound': { |
| 2602 |
'exchange': 'cpubound', |
| 2603 |
'routing_key': 'cpubound', |
| 2604 |
}, |
| 2605 |
} |
| 2606 |
|
| 2607 |
task_routes = { |
| 2608 |
'tasks.add': { |
| 2609 |
'queue': 'cpubound', |
| 2610 |
'routing_key': 'tasks.add', |
| 2611 |
'serializer': 'json', |
| 2612 |
}, |
| 2613 |
} |
| 2614 |
|
| 2615 |
The final routing options for ``tasks.add`` will become: |
| 2616 |
|
| 2617 |
.. code-block:: javascript |
| 2618 |
|
| 2619 |
{'exchange': 'cpubound', |
| 2620 |
'routing_key': 'tasks.add', |
| 2621 |
'serializer': 'json'} |
| 2622 |
|
| 2623 |
See :ref:`routers` for more examples. |
| 2624 |
|
| 2625 |
.. setting:: task_queue_max_priority |
| 2626 |
|
| 2627 |
``task_queue_max_priority`` |
| 2628 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2629 |
:brokers: RabbitMQ |
| 2630 |
|
| 2631 |
Default: :const:`None`. |
| 2632 |
|
| 2633 |
See :ref:`routing-options-rabbitmq-priorities`. |
| 2634 |
|
| 2635 |
.. setting:: task_default_priority |
| 2636 |
|
| 2637 |
``task_default_priority`` |
| 2638 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2639 |
:brokers: RabbitMQ, Redis |
| 2640 |
|
| 2641 |
Default: :const:`None`. |
| 2642 |
|
| 2643 |
See :ref:`routing-options-rabbitmq-priorities`. |
| 2644 |
|
| 2645 |
.. setting:: task_inherit_parent_priority |
| 2646 |
|
| 2647 |
``task_inherit_parent_priority`` |
| 2648 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2649 |
:brokers: RabbitMQ |
| 2650 |
|
| 2651 |
Default: :const:`False`. |
| 2652 |
|
| 2653 |
If enabled, child tasks will inherit priority of the parent task. |
| 2654 |
|
| 2655 |
.. code-block:: python |
| 2656 |
|
| 2657 |
# The last task in chain will also have priority set to 5. |
| 2658 |
chain = celery.chain(add.s(2) | add.s(2).set(priority=5) | add.s(3)) |
| 2659 |
|
| 2660 |
Priority inheritance also works when calling child tasks from a parent task |
| 2661 |
with `delay` or `apply_async`. |
| 2662 |
|
| 2663 |
See :ref:`routing-options-rabbitmq-priorities`. |
| 2664 |
|
| 2665 |
|
| 2666 |
.. setting:: worker_direct |
| 2667 |
|
| 2668 |
``worker_direct`` |
| 2669 |
~~~~~~~~~~~~~~~~~ |
| 2670 |
|
| 2671 |
Default: Disabled. |
| 2672 |
|
| 2673 |
This option enables so that every worker has a dedicated queue, |
| 2674 |
so that tasks can be routed to specific workers. |
| 2675 |
|
| 2676 |
The queue name for each worker is automatically generated based on |
| 2677 |
the worker hostname and a ``.dq`` suffix, using the ``C.dq2`` exchange. |
| 2678 |
|
| 2679 |
For example the queue name for the worker with node name ``[email protected]`` |
| 2680 |
becomes:: |
| 2681 |
|
| 2682 |
[email protected] |
| 2683 |
|
| 2684 |
Then you can route the task to the worker by specifying the hostname |
| 2685 |
as the routing key and the ``C.dq2`` exchange:: |
| 2686 |
|
| 2687 |
task_routes = { |
| 2688 |
'tasks.add': {'exchange': 'C.dq2', 'routing_key': '[email protected]'} |
| 2689 |
} |
| 2690 |
|
| 2691 |
.. setting:: task_create_missing_queues |
| 2692 |
|
| 2693 |
``task_create_missing_queues`` |
| 2694 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2695 |
|
| 2696 |
Default: Enabled. |
| 2697 |
|
| 2698 |
If enabled (default), any queues specified that aren't defined in |
| 2699 |
:setting:`task_queues` will be automatically created. See |
| 2700 |
:ref:`routing-automatic`. |
| 2701 |
|
| 2702 |
.. setting:: task_create_missing_queue_type |
| 2703 |
|
| 2704 |
``task_create_missing_queue_type`` |
| 2705 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2706 |
.. versionadded:: 5.6 |
| 2707 |
|
| 2708 |
Default: ``"classic"`` |
| 2709 |
|
| 2710 |
When Celery needs to declare a queue that doesn’t exist (i.e., when |
| 2711 |
``task_create_missing_queues`` is enabled), this setting defines what type |
| 2712 |
of RabbitMQ queue to create. |
| 2713 |
|
| 2714 |
- ``"classic"`` (default): declares a standard classic queue. |
| 2715 |
- ``"quorum"``: declares a RabbitMQ quorum queue (adds ``x-queue-type: quorum``). |
| 2716 |
|
| 2717 |
.. setting:: task_create_missing_queue_exchange_type |
| 2718 |
|
| 2719 |
``task_create_missing_queue_exchange_type`` |
| 2720 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2721 |
.. versionadded:: 5.6 |
| 2722 |
|
| 2723 |
Default: ``None`` |
| 2724 |
|
| 2725 |
If this option is None or the empty string (the default), Celery leaves the |
| 2726 |
exchange exactly as returned by your :attr:`app.amqp.Queues.autoexchange` |
| 2727 |
hook. |
| 2728 |
|
| 2729 |
You can set this to a specific exchange type, such as ``"direct"``, ``"topic"``, or |
| 2730 |
``"fanout"``, to create the missing queue with that exchange type. |
| 2731 |
|
| 2732 |
.. tip:: |
| 2733 |
|
| 2734 |
Combine this setting with task_create_missing_queue_type = "quorum" |
| 2735 |
to create quorum queues bound to a topic exchange, for example:: |
| 2736 |
|
| 2737 |
app.conf.task_create_missing_queues=True |
| 2738 |
app.conf.task_create_missing_queue_type="quorum" |
| 2739 |
app.conf.task_create_missing_queue_exchange_type="topic" |
| 2740 |
|
| 2741 |
.. note:: |
| 2742 |
|
| 2743 |
Like the queue-type setting above, this option does not affect queues |
| 2744 |
that you define explicitly in :setting:`task_queues`; it applies only to |
| 2745 |
queues created implicitly at runtime. |
| 2746 |
|
| 2747 |
.. setting:: task_default_queue |
| 2748 |
|
| 2749 |
``task_default_queue`` |
| 2750 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 2751 |
|
| 2752 |
Default: ``"celery"``. |
| 2753 |
|
| 2754 |
The name of the default queue used by `.apply_async` if the message has |
| 2755 |
no route or no custom queue has been specified. |
| 2756 |
|
| 2757 |
This queue must be listed in :setting:`task_queues`. |
| 2758 |
If :setting:`task_queues` isn't specified then it's automatically |
| 2759 |
created containing one queue entry, where this name is used as the name of |
| 2760 |
that queue. |
| 2761 |
|
| 2762 |
.. seealso:: |
| 2763 |
|
| 2764 |
:ref:`routing-changing-default-queue` |
| 2765 |
|
| 2766 |
.. setting:: task_default_queue_type |
| 2767 |
|
| 2768 |
``task_default_queue_type`` |
| 2769 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2770 |
|
| 2771 |
.. versionadded:: 5.5 |
| 2772 |
|
| 2773 |
Default: ``"classic"``. |
| 2774 |
|
| 2775 |
This setting is used to allow changing the default queue type for the |
| 2776 |
:setting:`task_default_queue` queue. The other viable option is ``"quorum"`` which |
| 2777 |
is only supported by RabbitMQ and sets the queue type to ``quorum`` using the ``x-queue-type`` |
| 2778 |
queue argument. |
| 2779 |
|
| 2780 |
If the :setting:`worker_detect_quorum_queues` setting is enabled, the worker will |
| 2781 |
automatically detect the queue type and disable the global QoS accordingly. |
| 2782 |
|
| 2783 |
.. warning:: |
| 2784 |
|
| 2785 |
Quorum queues require confirm publish to be enabled. |
| 2786 |
Use :setting:`broker_transport_options` to enable confirm publish by setting: |
| 2787 |
|
| 2788 |
.. code-block:: python |
| 2789 |
|
| 2790 |
broker_transport_options = {"confirm_publish": True} |
| 2791 |
|
| 2792 |
For more information, see `RabbitMQ documentation <https://www.rabbitmq.com/docs/quorum-queues#use-cases>`_. |
| 2793 |
|
| 2794 |
.. setting:: task_default_exchange |
| 2795 |
|
| 2796 |
``task_default_exchange`` |
| 2797 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2798 |
|
| 2799 |
Default: Uses the value set for :setting:`task_default_queue`. |
| 2800 |
|
| 2801 |
Name of the default exchange to use when no custom exchange is |
| 2802 |
specified for a key in the :setting:`task_queues` setting. |
| 2803 |
|
| 2804 |
.. setting:: task_default_exchange_type |
| 2805 |
|
| 2806 |
``task_default_exchange_type`` |
| 2807 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2808 |
|
| 2809 |
Default: ``"direct"``. |
| 2810 |
|
| 2811 |
Default exchange type used when no custom exchange type is specified |
| 2812 |
for a key in the :setting:`task_queues` setting. |
| 2813 |
|
| 2814 |
.. setting:: task_default_routing_key |
| 2815 |
|
| 2816 |
``task_default_routing_key`` |
| 2817 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2818 |
|
| 2819 |
Default: Uses the value set for :setting:`task_default_queue`. |
| 2820 |
|
| 2821 |
The default routing key used when no custom routing key |
| 2822 |
is specified for a key in the :setting:`task_queues` setting. |
| 2823 |
|
| 2824 |
.. setting:: task_default_delivery_mode |
| 2825 |
|
| 2826 |
``task_default_delivery_mode`` |
| 2827 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2828 |
|
| 2829 |
Default: ``"persistent"``. |
| 2830 |
|
| 2831 |
Can be `transient` (messages not written to disk) or `persistent` (written to |
| 2832 |
disk). |
| 2833 |
|
| 2834 |
.. _conf-broker-settings: |
| 2835 |
|
| 2836 |
Broker Settings |
| 2837 |
--------------- |
| 2838 |
|
| 2839 |
.. setting:: broker_url |
| 2840 |
|
| 2841 |
``broker_url`` |
| 2842 |
~~~~~~~~~~~~~~ |
| 2843 |
|
| 2844 |
Default: ``"amqp://"`` |
| 2845 |
|
| 2846 |
Default broker URL. This must be a URL in the form of:: |
| 2847 |
|
| 2848 |
transport://userid:password@hostname:port/virtual_host |
| 2849 |
|
| 2850 |
Only the scheme part (``transport://``) is required, the rest |
| 2851 |
is optional, and defaults to the specific transports default values. |
| 2852 |
|
| 2853 |
The transport part is the broker implementation to use, and the |
| 2854 |
default is ``amqp``, (uses ``librabbitmq`` if installed or falls back to |
| 2855 |
``pyamqp``). There are also other choices available, including; |
| 2856 |
``redis://``, ``sqs://``, and ``qpid://``. |
| 2857 |
|
| 2858 |
The scheme can also be a fully qualified path to your own transport |
| 2859 |
implementation:: |
| 2860 |
|
| 2861 |
broker_url = 'proj.transports.MyTransport://localhost' |
| 2862 |
|
| 2863 |
More than one broker URL, of the same transport, can also be specified. |
| 2864 |
The broker URLs can be passed in as a single string that's semicolon delimited:: |
| 2865 |
|
| 2866 |
broker_url = 'transport://userid:password@hostname:port//;transport://userid:password@hostname:port//' |
| 2867 |
|
| 2868 |
Or as a list:: |
| 2869 |
|
| 2870 |
broker_url = [ |
| 2871 |
'transport://userid:password@localhost:port//', |
| 2872 |
'transport://userid:password@hostname:port//' |
| 2873 |
] |
| 2874 |
|
| 2875 |
The brokers will then be used in the :setting:`broker_failover_strategy`. |
| 2876 |
|
| 2877 |
See :ref:`kombu:connection-urls` in the Kombu documentation for more |
| 2878 |
information. |
| 2879 |
|
| 2880 |
.. setting:: broker_read_url |
| 2881 |
|
| 2882 |
.. setting:: broker_write_url |
| 2883 |
|
| 2884 |
``broker_read_url`` / ``broker_write_url`` |
| 2885 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2886 |
|
| 2887 |
Default: Taken from :setting:`broker_url`. |
| 2888 |
|
| 2889 |
These settings can be configured, instead of :setting:`broker_url` to specify |
| 2890 |
different connection parameters for broker connections used for consuming and |
| 2891 |
producing. |
| 2892 |
|
| 2893 |
Example:: |
| 2894 |
|
| 2895 |
broker_read_url = 'amqp://user:[email protected]:56721' |
| 2896 |
broker_write_url = 'amqp://user:[email protected]:56722' |
| 2897 |
|
| 2898 |
Both options can also be specified as a list for failover alternates, see |
| 2899 |
:setting:`broker_url` for more information. |
| 2900 |
|
| 2901 |
.. setting:: broker_failover_strategy |
| 2902 |
|
| 2903 |
``broker_failover_strategy`` |
| 2904 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2905 |
|
| 2906 |
Default: ``"round-robin"``. |
| 2907 |
|
| 2908 |
Default failover strategy for the broker Connection object. If supplied, |
| 2909 |
may map to a key in 'kombu.connection.failover_strategies', or be a reference |
| 2910 |
to any method that yields a single item from a supplied list. |
| 2911 |
|
| 2912 |
Example:: |
| 2913 |
|
| 2914 |
# Random failover strategy |
| 2915 |
def random_failover_strategy(servers): |
| 2916 |
it = list(servers) # don't modify callers list |
| 2917 |
shuffle = random.shuffle |
| 2918 |
for _ in repeat(None): |
| 2919 |
shuffle(it) |
| 2920 |
yield it[0] |
| 2921 |
|
| 2922 |
broker_failover_strategy = random_failover_strategy |
| 2923 |
|
| 2924 |
.. setting:: broker_heartbeat |
| 2925 |
|
| 2926 |
``broker_heartbeat`` |
| 2927 |
~~~~~~~~~~~~~~~~~~~~ |
| 2928 |
:transports supported: ``pyamqp`` |
| 2929 |
|
| 2930 |
Default: ``120.0`` (negotiated by server). |
| 2931 |
|
| 2932 |
Note: This value is only used by the worker, clients do not use |
| 2933 |
a heartbeat at the moment. |
| 2934 |
|
| 2935 |
It's not always possible to detect connection loss in a timely |
| 2936 |
manner using TCP/IP alone, so AMQP defines something called heartbeats |
| 2937 |
that's is used both by the client and the broker to detect if |
| 2938 |
a connection was closed. |
| 2939 |
|
| 2940 |
If the heartbeat value is 10 seconds, then |
| 2941 |
the heartbeat will be monitored at the interval specified |
| 2942 |
by the :setting:`broker_heartbeat_checkrate` setting (by default |
| 2943 |
this is set to double the rate of the heartbeat value, |
| 2944 |
so for the 10 seconds, the heartbeat is checked every 5 seconds). |
| 2945 |
|
| 2946 |
.. setting:: broker_heartbeat_checkrate |
| 2947 |
|
| 2948 |
``broker_heartbeat_checkrate`` |
| 2949 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2950 |
:transports supported: ``pyamqp`` |
| 2951 |
|
| 2952 |
Default: 2.0. |
| 2953 |
|
| 2954 |
At intervals the worker will monitor that the broker hasn't missed |
| 2955 |
too many heartbeats. The rate at which this is checked is calculated |
| 2956 |
by dividing the :setting:`broker_heartbeat` value with this value, |
| 2957 |
so if the heartbeat is 10.0 and the rate is the default 2.0, the check |
| 2958 |
will be performed every 5 seconds (twice the heartbeat sending rate). |
| 2959 |
|
| 2960 |
.. setting:: broker_use_ssl |
| 2961 |
|
| 2962 |
``broker_use_ssl`` |
| 2963 |
~~~~~~~~~~~~~~~~~~ |
| 2964 |
:transports supported: ``pyamqp``, ``redis`` |
| 2965 |
|
| 2966 |
Default: Disabled. |
| 2967 |
|
| 2968 |
Toggles SSL usage on broker connection and SSL settings. |
| 2969 |
|
| 2970 |
The valid values for this option vary by transport. |
| 2971 |
|
| 2972 |
``pyamqp`` |
| 2973 |
__________ |
| 2974 |
|
| 2975 |
If ``True`` the connection will use SSL with default SSL settings. |
| 2976 |
If set to a dict, will configure SSL connection according to the specified |
| 2977 |
policy. The format used is Python's :func:`ssl.wrap_socket` options. |
| 2978 |
|
| 2979 |
Note that SSL socket is generally served on a separate port by the broker. |
| 2980 |
|
| 2981 |
Example providing a client cert and validating the server cert against a custom |
| 2982 |
certificate authority: |
| 2983 |
|
| 2984 |
.. code-block:: python |
| 2985 |
|
| 2986 |
import ssl |
| 2987 |
|
| 2988 |
broker_use_ssl = { |
| 2989 |
'keyfile': '/var/ssl/private/worker-key.pem', |
| 2990 |
'certfile': '/var/ssl/amqp-server-cert.pem', |
| 2991 |
'ca_certs': '/var/ssl/myca.pem', |
| 2992 |
'cert_reqs': ssl.CERT_REQUIRED |
| 2993 |
} |
| 2994 |
|
| 2995 |
.. versionadded:: 5.1 |
| 2996 |
|
| 2997 |
Starting from Celery 5.1, py-amqp will always validate certificates received from the server |
| 2998 |
and it is no longer required to manually set ``cert_reqs`` to ``ssl.CERT_REQUIRED``. |
| 2999 |
|
| 3000 |
The previous default, ``ssl.CERT_NONE`` is insecure and we its usage should be discouraged. |
| 3001 |
If you'd like to revert to the previous insecure default set ``cert_reqs`` to ``ssl.CERT_NONE`` |
| 3002 |
|
| 3003 |
|
| 3004 |
``redis`` |
| 3005 |
_________ |
| 3006 |
|
| 3007 |
|
| 3008 |
The setting must be a dict with the following keys: |
| 3009 |
|
| 3010 |
* ``ssl_cert_reqs`` (required): one of the ``SSLContext.verify_mode`` values: |
| 3011 |
* ``ssl.CERT_NONE`` |
| 3012 |
* ``ssl.CERT_OPTIONAL`` |
| 3013 |
* ``ssl.CERT_REQUIRED`` |
| 3014 |
* ``ssl_ca_certs`` (optional): path to the CA certificate |
| 3015 |
* ``ssl_certfile`` (optional): path to the client certificate |
| 3016 |
* ``ssl_keyfile`` (optional): path to the client key |
| 3017 |
|
| 3018 |
|
| 3019 |
.. setting:: broker_pool_limit |
| 3020 |
|
| 3021 |
``broker_pool_limit`` |
| 3022 |
~~~~~~~~~~~~~~~~~~~~~ |
| 3023 |
|
| 3024 |
.. versionadded:: 2.3 |
| 3025 |
|
| 3026 |
Default: 10. |
| 3027 |
|
| 3028 |
The maximum number of connections that can be open in the connection pool. |
| 3029 |
|
| 3030 |
The pool is enabled by default since version 2.5, with a default limit of ten |
| 3031 |
connections. This number can be tweaked depending on the number of |
| 3032 |
threads/green-threads (eventlet/gevent) using a connection. For example |
| 3033 |
running eventlet with 1000 greenlets that use a connection to the broker, |
| 3034 |
contention can arise and you should consider increasing the limit. |
| 3035 |
|
| 3036 |
If set to :const:`None` or 0 the connection pool will be disabled and |
| 3037 |
connections will be established and closed for every use. |
| 3038 |
|
| 3039 |
.. setting:: broker_connection_timeout |
| 3040 |
|
| 3041 |
``broker_connection_timeout`` |
| 3042 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3043 |
|
| 3044 |
Default: 4.0. |
| 3045 |
|
| 3046 |
The default timeout in seconds before we give up establishing a connection |
| 3047 |
to the AMQP server. This setting is disabled when using |
| 3048 |
gevent. |
| 3049 |
|
| 3050 |
.. note:: |
| 3051 |
|
| 3052 |
The broker connection timeout only applies to a worker attempting to |
| 3053 |
connect to the broker. It does not apply to producer sending a task, see |
| 3054 |
:setting:`broker_transport_options` for how to provide a timeout for that |
| 3055 |
situation. |
| 3056 |
|
| 3057 |
.. setting:: broker_connection_retry |
| 3058 |
|
| 3059 |
``broker_connection_retry`` |
| 3060 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3061 |
|
| 3062 |
Default: Enabled. |
| 3063 |
|
| 3064 |
Automatically try to re-establish the connection to the AMQP broker if lost |
| 3065 |
after the initial connection is made. |
| 3066 |
|
| 3067 |
The time between retries is increased for each retry, and is |
| 3068 |
not exhausted before :setting:`broker_connection_max_retries` is |
| 3069 |
exceeded. |
| 3070 |
|
| 3071 |
.. warning:: |
| 3072 |
|
| 3073 |
The broker_connection_retry configuration setting will no longer determine |
| 3074 |
whether broker connection retries are made during startup in Celery 6.0 and above. |
| 3075 |
If you wish to refrain from retrying connections on startup, |
| 3076 |
you should set broker_connection_retry_on_startup to False instead. |
| 3077 |
|
| 3078 |
.. setting:: broker_connection_retry_on_startup |
| 3079 |
|
| 3080 |
``broker_connection_retry_on_startup`` |
| 3081 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3082 |
|
| 3083 |
Default: Enabled. |
| 3084 |
|
| 3085 |
Automatically try to establish the connection to the AMQP broker on Celery startup if it is unavailable. |
| 3086 |
|
| 3087 |
The time between retries is increased for each retry, and is |
| 3088 |
not exhausted before :setting:`broker_connection_max_retries` is |
| 3089 |
exceeded. |
| 3090 |
|
| 3091 |
.. setting:: broker_connection_max_retries |
| 3092 |
|
| 3093 |
``broker_connection_max_retries`` |
| 3094 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3095 |
|
| 3096 |
Default: 100. |
| 3097 |
|
| 3098 |
Maximum number of retries before we give up re-establishing a connection |
| 3099 |
to the AMQP broker. |
| 3100 |
|
| 3101 |
If this is set to :const:`None`, we'll retry forever. |
| 3102 |
|
| 3103 |
``broker_channel_error_retry`` |
| 3104 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3105 |
|
| 3106 |
.. versionadded:: 5.3 |
| 3107 |
|
| 3108 |
Default: Disabled. |
| 3109 |
|
| 3110 |
Automatically try to re-establish the connection to the AMQP broker |
| 3111 |
if any invalid response has been returned. |
| 3112 |
|
| 3113 |
The retry count and interval is the same as that of `broker_connection_retry`. |
| 3114 |
Also, this option doesn't work when `broker_connection_retry` is `False`. |
| 3115 |
|
| 3116 |
.. setting:: broker_login_method |
| 3117 |
|
| 3118 |
``broker_login_method`` |
| 3119 |
~~~~~~~~~~~~~~~~~~~~~~~ |
| 3120 |
|
| 3121 |
Default: ``"AMQPLAIN"``. |
| 3122 |
|
| 3123 |
Set custom amqp login method. |
| 3124 |
|
| 3125 |
.. setting:: broker_native_delayed_delivery_queue_type |
| 3126 |
|
| 3127 |
``broker_native_delayed_delivery_queue_type`` |
| 3128 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3129 |
|
| 3130 |
.. versionadded:: 5.5 |
| 3131 |
|
| 3132 |
:transports supported: ``pyamqp`` |
| 3133 |
|
| 3134 |
Default: ``"quorum"``. |
| 3135 |
|
| 3136 |
This setting is used to allow changing the default queue type for the |
| 3137 |
native delayed delivery queues. The other viable option is ``"classic"`` which |
| 3138 |
is only supported by RabbitMQ and sets the queue type to ``classic`` using the ``x-queue-type`` |
| 3139 |
queue argument. |
| 3140 |
|
| 3141 |
.. setting:: broker_transport_options |
| 3142 |
|
| 3143 |
``broker_transport_options`` |
| 3144 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3145 |
|
| 3146 |
.. versionadded:: 2.2 |
| 3147 |
|
| 3148 |
Default: ``{}`` (empty mapping). |
| 3149 |
|
| 3150 |
A dict of additional options passed to the underlying transport. |
| 3151 |
|
| 3152 |
See your transport user manual for supported options (if any). |
| 3153 |
|
| 3154 |
Example setting the visibility timeout (supported by Redis and SQS |
| 3155 |
transports): |
| 3156 |
|
| 3157 |
.. code-block:: python |
| 3158 |
|
| 3159 |
broker_transport_options = {'visibility_timeout': 18000} # 5 hours |
| 3160 |
|
| 3161 |
Example setting the producer connection maximum number of retries (so producers |
| 3162 |
won't retry forever if the broker isn't available at the first task execution): |
| 3163 |
|
| 3164 |
.. code-block:: python |
| 3165 |
|
| 3166 |
broker_transport_options = {'max_retries': 5} |
| 3167 |
|
| 3168 |
Example enabling publisher confirms (supported by the ``pyamqp`` transport). |
| 3169 |
Without this, messages can be silently dropped when the broker hits resource |
| 3170 |
limits: |
| 3171 |
|
| 3172 |
.. code-block:: python |
| 3173 |
|
| 3174 |
broker_transport_options = {'confirm_publish': True} |
| 3175 |
|
| 3176 |
.. _conf-worker: |
| 3177 |
|
| 3178 |
Worker |
| 3179 |
------ |
| 3180 |
|
| 3181 |
.. setting:: imports |
| 3182 |
|
| 3183 |
``imports`` |
| 3184 |
~~~~~~~~~~~ |
| 3185 |
|
| 3186 |
Default: ``[]`` (empty list). |
| 3187 |
|
| 3188 |
A sequence of modules to import when the worker starts. |
| 3189 |
|
| 3190 |
This is used to specify the task modules to import, but also |
| 3191 |
to import signal handlers and additional remote control commands, etc. |
| 3192 |
|
| 3193 |
The modules will be imported in the original order. |
| 3194 |
|
| 3195 |
.. setting:: include |
| 3196 |
|
| 3197 |
``include`` |
| 3198 |
~~~~~~~~~~~ |
| 3199 |
|
| 3200 |
Default: ``[]`` (empty list). |
| 3201 |
|
| 3202 |
Exact same semantics as :setting:`imports`, but can be used as a means |
| 3203 |
to have different import categories. |
| 3204 |
|
| 3205 |
The modules in this setting are imported after the modules in |
| 3206 |
:setting:`imports`. |
| 3207 |
|
| 3208 |
.. setting:: worker_deduplicate_successful_tasks |
| 3209 |
|
| 3210 |
``worker_deduplicate_successful_tasks`` |
| 3211 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3212 |
|
| 3213 |
.. versionadded:: 5.1 |
| 3214 |
|
| 3215 |
Default: False |
| 3216 |
|
| 3217 |
Before each task execution, instruct the worker to check if this task is |
| 3218 |
a duplicate message. |
| 3219 |
|
| 3220 |
Deduplication occurs only with tasks that have the same identifier, |
| 3221 |
enabled late acknowledgment, were redelivered by the message broker |
| 3222 |
and their state is ``SUCCESS`` in the result backend. |
| 3223 |
|
| 3224 |
To avoid overflowing the result backend with queries, a local cache of |
| 3225 |
successfully executed tasks is checked before querying the result backend |
| 3226 |
in case the task was already successfully executed by the same worker that |
| 3227 |
received the task. |
| 3228 |
|
| 3229 |
This cache can be made persistent by setting the :setting:`worker_state_db` |
| 3230 |
setting. |
| 3231 |
|
| 3232 |
If the result backend is not `persistent <https://github.com/celery/celery/blob/main/celery/backends/base.py#L102>`_ |
| 3233 |
(the RPC backend, for example), this setting is ignored. |
| 3234 |
|
| 3235 |
.. _conf-concurrency: |
| 3236 |
|
| 3237 |
.. setting:: worker_concurrency |
| 3238 |
|
| 3239 |
``worker_concurrency`` |
| 3240 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 3241 |
|
| 3242 |
Default: Number of CPU cores. |
| 3243 |
|
| 3244 |
The number of concurrent worker processes/threads/green threads executing |
| 3245 |
tasks. |
| 3246 |
|
| 3247 |
If you're doing mostly I/O you can have more processes, |
| 3248 |
but if mostly CPU-bound, try to keep it close to the |
| 3249 |
number of CPUs on your machine. If not set, the number of CPUs/cores |
| 3250 |
on the host will be used. |
| 3251 |
|
| 3252 |
.. setting:: worker_prefetch_multiplier |
| 3253 |
|
| 3254 |
``worker_prefetch_multiplier`` |
| 3255 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3256 |
|
| 3257 |
Default: 4. |
| 3258 |
|
| 3259 |
How many messages to prefetch at a time multiplied by the number of |
| 3260 |
concurrent processes. The default is 4 (four messages for each |
| 3261 |
process). The default setting is usually a good choice, however -- if you |
| 3262 |
have very long running tasks waiting in the queue and you have to start the |
| 3263 |
workers, note that the first worker to start will receive four times the |
| 3264 |
number of messages initially. Thus the tasks may not be fairly distributed |
| 3265 |
to the workers. |
| 3266 |
|
| 3267 |
To limit the broker to only deliver one message per process at a time, |
| 3268 |
set :setting:`worker_prefetch_multiplier` to 1. Changing that setting to 0 |
| 3269 |
will allow the worker to keep consuming as many messages as it wants. |
| 3270 |
|
| 3271 |
If you need to completely disable broker prefetching while still using |
| 3272 |
early acknowledgments, enable :setting:`worker_disable_prefetch`. |
| 3273 |
When this option is enabled the worker only fetches a task from the broker |
| 3274 |
when one of its processes is available. |
| 3275 |
|
| 3276 |
.. note:: |
| 3277 |
|
| 3278 |
This feature is currently only supported when using Redis as the broker. |
| 3279 |
|
| 3280 |
You can also enable this via the :option:`--disable-prefetch <celery worker --disable-prefetch>` |
| 3281 |
command line flag. |
| 3282 |
|
| 3283 |
For more on prefetching, read :ref:`optimizing-prefetch-limit` |
| 3284 |
|
| 3285 |
.. setting:: worker_eta_task_limit |
| 3286 |
|
| 3287 |
``worker_eta_task_limit`` |
| 3288 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3289 |
|
| 3290 |
.. versionadded:: 5.6 |
| 3291 |
|
| 3292 |
Default: No limit (None). |
| 3293 |
|
| 3294 |
The maximum number of ETA/countdown tasks that a worker can hold in memory at once. |
| 3295 |
When this limit is reached, the worker will not receive new tasks from the broker |
| 3296 |
until some of the existing ETA tasks are executed. |
| 3297 |
|
| 3298 |
This setting helps prevent memory exhaustion when a queue contains a large number |
| 3299 |
of tasks with ETA/countdown values, as these tasks are held in memory until their |
| 3300 |
execution time. Without this limit, workers may fetch thousands of ETA tasks into |
| 3301 |
memory, potentially causing out-of-memory issues. |
| 3302 |
|
| 3303 |
.. note:: |
| 3304 |
|
| 3305 |
Tasks with ETA/countdown are fetched into memory and scheduled on an internal |
| 3306 |
timer, so they are not constrained by the per-process prefetch window derived |
| 3307 |
from :setting:`worker_prefetch_multiplier` in the same way as immediately |
| 3308 |
executed tasks. This is why ``--prefetch-multiplier=1`` can appear to have no |
| 3309 |
effect when many ETA/countdown tasks are present. |
| 3310 |
|
| 3311 |
:setting:`worker_eta_task_limit` configures the maximum number of ETA/countdown |
| 3312 |
tasks a worker will hold in memory and also sets an overall cap on |
| 3313 |
unacknowledged messages via kombu's QoS ``max_prefetch``. If the prefetch count |
| 3314 |
implied by :setting:`worker_prefetch_multiplier` would exceed this cap, the |
| 3315 |
worker will stop consuming new messages until previously received tasks have |
| 3316 |
been acknowledged. |
| 3317 |
.. setting:: worker_disable_prefetch |
| 3318 |
|
| 3319 |
``worker_disable_prefetch`` |
| 3320 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3321 |
|
| 3322 |
.. versionadded:: 5.6 |
| 3323 |
|
| 3324 |
Default: ``False``. |
| 3325 |
|
| 3326 |
When enabled, a worker will only consume messages from the broker when it |
| 3327 |
has an available process to execute them. This disables prefetching while |
| 3328 |
still using early acknowledgments, ensuring that tasks are fairly |
| 3329 |
distributed between workers. |
| 3330 |
|
| 3331 |
.. note:: |
| 3332 |
|
| 3333 |
This feature is currently only supported when using Redis as the broker. |
| 3334 |
Using this setting with other brokers will result in a warning and the |
| 3335 |
setting will be ignored. |
| 3336 |
|
| 3337 |
.. setting:: worker_enable_prefetch_count_reduction |
| 3338 |
|
| 3339 |
``worker_enable_prefetch_count_reduction`` |
| 3340 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3341 |
|
| 3342 |
.. versionadded:: 5.4 |
| 3343 |
|
| 3344 |
Default: Enabled. |
| 3345 |
|
| 3346 |
The ``worker_enable_prefetch_count_reduction`` setting governs the restoration behavior of the |
| 3347 |
prefetch count to its maximum allowable value following a connection loss to the message |
| 3348 |
broker. By default, this setting is enabled. |
| 3349 |
|
| 3350 |
Upon a connection loss, Celery will attempt to reconnect to the broker automatically, |
| 3351 |
provided the :setting:`broker_connection_retry_on_startup` or :setting:`broker_connection_retry` |
| 3352 |
is not set to False. During the period of lost connection, the message broker does not keep track |
| 3353 |
of the number of tasks already fetched. Therefore, to manage the task load effectively and prevent |
| 3354 |
overloading, Celery reduces the prefetch count based on the number of tasks that are |
| 3355 |
currently running. |
| 3356 |
|
| 3357 |
The prefetch count is the number of messages that a worker will fetch from the broker at |
| 3358 |
a time. The reduced prefetch count helps ensure that tasks are not fetched excessively |
| 3359 |
during periods of reconnection. |
| 3360 |
|
| 3361 |
With ``worker_enable_prefetch_count_reduction`` set to its default value (Enabled), the prefetch |
| 3362 |
count will be gradually restored to its maximum allowed value each time a task that was |
| 3363 |
running before the connection was lost is completed. This behavior helps maintain a |
| 3364 |
balanced distribution of tasks among the workers while managing the load effectively. |
| 3365 |
|
| 3366 |
To disable the reduction and restoration of the prefetch count to its maximum allowed value on |
| 3367 |
reconnection, set ``worker_enable_prefetch_count_reduction`` to False. Disabling this setting might |
| 3368 |
be useful in scenarios where a fixed prefetch count is desired to control the rate of task |
| 3369 |
processing or manage the worker load, especially in environments with fluctuating connectivity. |
| 3370 |
|
| 3371 |
The ``worker_enable_prefetch_count_reduction`` setting provides a way to control the |
| 3372 |
restoration behavior of the prefetch count following a connection loss, aiding in |
| 3373 |
maintaining a balanced task distribution and effective load management across the workers. |
| 3374 |
|
| 3375 |
.. setting:: worker_lost_wait |
| 3376 |
|
| 3377 |
``worker_lost_wait`` |
| 3378 |
~~~~~~~~~~~~~~~~~~~~ |
| 3379 |
|
| 3380 |
Default: 10.0 seconds. |
| 3381 |
|
| 3382 |
In some cases a worker may be killed without proper cleanup, |
| 3383 |
and the worker may have published a result before terminating. |
| 3384 |
This value specifies how long we wait for any missing results before |
| 3385 |
raising a :exc:`@WorkerLostError` exception. |
| 3386 |
|
| 3387 |
.. setting:: worker_max_tasks_per_child |
| 3388 |
|
| 3389 |
``worker_max_tasks_per_child`` |
| 3390 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3391 |
|
| 3392 |
Maximum number of tasks a pool worker process can execute before |
| 3393 |
it's replaced with a new one. Default is no limit. |
| 3394 |
|
| 3395 |
.. setting:: worker_max_memory_per_child |
| 3396 |
|
| 3397 |
``worker_max_memory_per_child`` |
| 3398 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3399 |
|
| 3400 |
Default: No limit. |
| 3401 |
Type: int (kilobytes) |
| 3402 |
|
| 3403 |
Maximum amount of resident memory, in kilobytes (1024 bytes), that may be |
| 3404 |
consumed by a worker before it will be replaced by a new worker. If a single |
| 3405 |
task causes a worker to exceed this limit, the task will be completed, and the |
| 3406 |
worker will be replaced afterwards. |
| 3407 |
|
| 3408 |
Example: |
| 3409 |
|
| 3410 |
.. code-block:: python |
| 3411 |
|
| 3412 |
worker_max_memory_per_child = 12288 # 12 * 1024 = 12 MB |
| 3413 |
|
| 3414 |
.. setting:: worker_disable_rate_limits |
| 3415 |
|
| 3416 |
``worker_disable_rate_limits`` |
| 3417 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3418 |
|
| 3419 |
Default: Disabled (rate limits enabled). |
| 3420 |
|
| 3421 |
Disable all rate limits, even if tasks has explicit rate limits set. |
| 3422 |
|
| 3423 |
.. setting:: worker_state_db |
| 3424 |
|
| 3425 |
``worker_state_db`` |
| 3426 |
~~~~~~~~~~~~~~~~~~~ |
| 3427 |
|
| 3428 |
Default: :const:`None`. |
| 3429 |
|
| 3430 |
Name of the file used to stores persistent worker state (like revoked tasks). |
| 3431 |
Can be a relative or absolute path, but be aware that the suffix `.db` |
| 3432 |
may be appended to the file name (depending on Python version). |
| 3433 |
|
| 3434 |
Can also be set via the :option:`celery worker --statedb` argument. |
| 3435 |
|
| 3436 |
.. setting:: worker_timer_precision |
| 3437 |
|
| 3438 |
``worker_timer_precision`` |
| 3439 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3440 |
|
| 3441 |
Default: 1.0 seconds. |
| 3442 |
|
| 3443 |
Set the maximum time in seconds that the ETA scheduler can sleep between |
| 3444 |
rechecking the schedule. |
| 3445 |
|
| 3446 |
Setting this value to 1 second means the schedulers precision will |
| 3447 |
be 1 second. If you need near millisecond precision you can set this to 0.1. |
| 3448 |
|
| 3449 |
.. setting:: worker_enable_remote_control |
| 3450 |
|
| 3451 |
``worker_enable_remote_control`` |
| 3452 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3453 |
|
| 3454 |
Default: Enabled by default. |
| 3455 |
|
| 3456 |
Specify if remote control of the workers is enabled. |
| 3457 |
|
| 3458 |
.. setting:: worker_proc_alive_timeout |
| 3459 |
|
| 3460 |
``worker_proc_alive_timeout`` |
| 3461 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3462 |
|
| 3463 |
Default: 4.0. |
| 3464 |
|
| 3465 |
The timeout in seconds (int/float) when waiting for a new worker process to start up. |
| 3466 |
|
| 3467 |
.. setting:: worker_cancel_long_running_tasks_on_connection_loss |
| 3468 |
|
| 3469 |
``worker_cancel_long_running_tasks_on_connection_loss`` |
| 3470 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3471 |
|
| 3472 |
.. versionadded:: 5.1 |
| 3473 |
|
| 3474 |
Default: Disabled by default. |
| 3475 |
|
| 3476 |
Kill all long-running tasks with late acknowledgment enabled on connection loss. |
| 3477 |
|
| 3478 |
Tasks which have not been acknowledged before the connection loss cannot do so |
| 3479 |
anymore since their channel is gone and the task is redelivered back to the queue. |
| 3480 |
This is why tasks with late acknowledged enabled must be idempotent as they may be executed more than once. |
| 3481 |
In this case, the task is being executed twice per connection loss (and sometimes in parallel in other workers). |
| 3482 |
|
| 3483 |
When turning this option on, those tasks which have not been completed are |
| 3484 |
cancelled and their execution is terminated. |
| 3485 |
Tasks which have completed in any way before the connection loss |
| 3486 |
are recorded as such in the result backend as long as :setting:`task_ignore_result` is not enabled. |
| 3487 |
|
| 3488 |
.. warning:: |
| 3489 |
|
| 3490 |
This feature was introduced as a future breaking change. |
| 3491 |
If it is turned off, Celery will emit a warning message. |
| 3492 |
|
| 3493 |
In Celery 6.0, the :setting:`worker_cancel_long_running_tasks_on_connection_loss` |
| 3494 |
will be set to ``True`` by default as the current behavior leads to more |
| 3495 |
problems than it solves. |
| 3496 |
|
| 3497 |
.. setting:: worker_detect_quorum_queues |
| 3498 |
|
| 3499 |
``worker_detect_quorum_queues`` |
| 3500 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3501 |
|
| 3502 |
.. versionadded:: 5.5 |
| 3503 |
|
| 3504 |
Default: Enabled. |
| 3505 |
|
| 3506 |
Automatically detect if any of the queues in :setting:`task_queues` are quorum queues |
| 3507 |
(including the :setting:`task_default_queue`) and disable the global QoS if any quorum queue is detected. |
| 3508 |
|
| 3509 |
.. setting:: worker_soft_shutdown_timeout |
| 3510 |
|
| 3511 |
``worker_soft_shutdown_timeout`` |
| 3512 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3513 |
|
| 3514 |
.. versionadded:: 5.5 |
| 3515 |
|
| 3516 |
Default: 0.0. |
| 3517 |
|
| 3518 |
The standard :ref:`warm shutdown <worker-warm-shutdown>` will wait for all tasks to finish before shutting down |
| 3519 |
unless the cold shutdown is triggered. The :ref:`soft shutdown <worker-soft-shutdown>` will add a waiting time |
| 3520 |
before the cold shutdown is initiated. This setting specifies how long the worker will wait before the cold shutdown |
| 3521 |
is initiated and the worker is terminated. |
| 3522 |
|
| 3523 |
This will apply also when the worker initiate :ref:`cold shutdown <worker-cold-shutdown>` without doing a warm shutdown first. |
| 3524 |
|
| 3525 |
If the value is set to 0.0, the soft shutdown will be practically disabled. Regardless of the value, the soft shutdown |
| 3526 |
will be disabled if there are no tasks running (unless :setting:`worker_enable_soft_shutdown_on_idle` is enabled). |
| 3527 |
|
| 3528 |
Experiment with this value to find the optimal time for your tasks to finish gracefully before the worker is terminated. |
| 3529 |
Recommended values can be 10, 30, 60 seconds. Too high value can lead to a long waiting time before the worker is terminated |
| 3530 |
and trigger a :sig:`KILL` signal to forcefully terminate the worker by the host system. |
| 3531 |
|
| 3532 |
.. setting:: worker_enable_soft_shutdown_on_idle |
| 3533 |
|
| 3534 |
``worker_enable_soft_shutdown_on_idle`` |
| 3535 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3536 |
|
| 3537 |
.. versionadded:: 5.5 |
| 3538 |
|
| 3539 |
Default: False. |
| 3540 |
|
| 3541 |
If the :setting:`worker_soft_shutdown_timeout` is set to a value greater than 0.0, the worker will skip |
| 3542 |
the :ref:`soft shutdown <worker-soft-shutdown>` anyways if there are no tasks running. This setting will |
| 3543 |
enable the soft shutdown even if there are no tasks running. |
| 3544 |
|
| 3545 |
.. tip:: |
| 3546 |
|
| 3547 |
When the worker received ETA tasks, but the ETA has not been reached yet, and a shutdown is initiated, |
| 3548 |
the worker will **skip** the soft shutdown and initiate the cold shutdown immediately if there are no |
| 3549 |
tasks running. This may lead to failure in re-queueing the ETA tasks during worker teardown. To mitigate |
| 3550 |
this, enable this configuration to ensure the worker waits regadless, which gives enough time for a |
| 3551 |
graceful shutdown and successful re-queueing of the ETA tasks. |
| 3552 |
|
| 3553 |
.. _conf-events: |
| 3554 |
|
| 3555 |
Events |
| 3556 |
------ |
| 3557 |
|
| 3558 |
.. setting:: worker_send_task_events |
| 3559 |
|
| 3560 |
``worker_send_task_events`` |
| 3561 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3562 |
|
| 3563 |
Default: Disabled by default. |
| 3564 |
|
| 3565 |
Send task-related events so that tasks can be monitored using tools like |
| 3566 |
`flower`. Sets the default value for the workers |
| 3567 |
:option:`-E <celery worker -E>` argument. |
| 3568 |
|
| 3569 |
.. setting:: task_send_sent_event |
| 3570 |
|
| 3571 |
``task_send_sent_event`` |
| 3572 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3573 |
|
| 3574 |
.. versionadded:: 2.2 |
| 3575 |
|
| 3576 |
Default: Disabled by default. |
| 3577 |
|
| 3578 |
If enabled, a :event:`task-sent` event will be sent for every task so tasks can be |
| 3579 |
tracked before they're consumed by a worker. |
| 3580 |
|
| 3581 |
.. setting:: event_queue_ttl |
| 3582 |
|
| 3583 |
``event_queue_ttl`` |
| 3584 |
~~~~~~~~~~~~~~~~~~~ |
| 3585 |
:transports supported: ``amqp`` |
| 3586 |
|
| 3587 |
Default: 5.0 seconds. |
| 3588 |
|
| 3589 |
Message expiry time in seconds (int/float) for when messages sent to a monitor clients |
| 3590 |
event queue is deleted (``x-message-ttl``) |
| 3591 |
|
| 3592 |
For example, if this value is set to 10 then a message delivered to this queue |
| 3593 |
will be deleted after 10 seconds. |
| 3594 |
|
| 3595 |
.. setting:: event_queue_expires |
| 3596 |
|
| 3597 |
``event_queue_expires`` |
| 3598 |
~~~~~~~~~~~~~~~~~~~~~~~ |
| 3599 |
:transports supported: ``amqp`` |
| 3600 |
|
| 3601 |
Default: 60.0 seconds. |
| 3602 |
|
| 3603 |
Expiry time in seconds (int/float) for when after a monitor clients |
| 3604 |
event queue will be deleted (``x-expires``). |
| 3605 |
|
| 3606 |
.. setting:: event_queue_durable |
| 3607 |
|
| 3608 |
``event_queue_durable`` |
| 3609 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3610 |
:transports supported: ``amqp`` |
| 3611 |
.. versionadded:: 5.6 |
| 3612 |
|
| 3613 |
Default: ``False`` |
| 3614 |
|
| 3615 |
If enabled, the event receiver's queue will be marked as *durable*, meaning it will survive broker restarts. |
| 3616 |
|
| 3617 |
.. setting:: event_queue_exclusive |
| 3618 |
|
| 3619 |
``event_queue_exclusive`` |
| 3620 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3621 |
:transports supported: ``amqp`` |
| 3622 |
.. versionadded:: 5.6 |
| 3623 |
|
| 3624 |
Default: ``False`` |
| 3625 |
|
| 3626 |
If enabled, the event queue will be *exclusive* to the current connection and automatically deleted when the connection closes. |
| 3627 |
|
| 3628 |
.. warning:: |
| 3629 |
|
| 3630 |
You **cannot** set both ``event_queue_durable`` and ``event_queue_exclusive`` to ``True`` at the same time. |
| 3631 |
Celery will raise an :exc:`ImproperlyConfigured` error if both are set. |
| 3632 |
|
| 3633 |
.. setting:: event_queue_prefix |
| 3634 |
|
| 3635 |
``event_queue_prefix`` |
| 3636 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 3637 |
|
| 3638 |
Default: ``"celeryev"``. |
| 3639 |
|
| 3640 |
The prefix to use for event receiver queue names. |
| 3641 |
|
| 3642 |
.. setting:: event_exchange |
| 3643 |
|
| 3644 |
``event_exchange`` |
| 3645 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 3646 |
|
| 3647 |
Default: ``"celeryev"``. |
| 3648 |
|
| 3649 |
Name of the event exchange. |
| 3650 |
|
| 3651 |
.. warning:: |
| 3652 |
|
| 3653 |
This option is in experimental stage, please use it with caution. |
| 3654 |
|
| 3655 |
.. setting:: event_serializer |
| 3656 |
|
| 3657 |
``event_serializer`` |
| 3658 |
~~~~~~~~~~~~~~~~~~~~ |
| 3659 |
|
| 3660 |
Default: ``"json"``. |
| 3661 |
|
| 3662 |
Message serialization format used when sending event messages. |
| 3663 |
|
| 3664 |
.. seealso:: |
| 3665 |
|
| 3666 |
:ref:`calling-serializers`. |
| 3667 |
|
| 3668 |
|
| 3669 |
.. setting:: events_logfile |
| 3670 |
|
| 3671 |
``events_logfile`` |
| 3672 |
~~~~~~~~~~~~~~~~~~ |
| 3673 |
|
| 3674 |
.. versionadded:: 5.4 |
| 3675 |
|
| 3676 |
Default: :const:`None` |
| 3677 |
|
| 3678 |
An optional file path for :program:`celery events` to log into (defaults to `stdout`). |
| 3679 |
|
| 3680 |
.. setting:: events_pidfile |
| 3681 |
|
| 3682 |
``events_pidfile`` |
| 3683 |
~~~~~~~~~~~~~~~~~~ |
| 3684 |
|
| 3685 |
.. versionadded:: 5.4 |
| 3686 |
|
| 3687 |
Default: :const:`None` |
| 3688 |
|
| 3689 |
An optional file path for :program:`celery events` to create/store its PID file (default to no PID file created). |
| 3690 |
|
| 3691 |
.. setting:: events_uid |
| 3692 |
|
| 3693 |
``events_uid`` |
| 3694 |
~~~~~~~~~~~~~~ |
| 3695 |
|
| 3696 |
.. versionadded:: 5.4 |
| 3697 |
|
| 3698 |
Default: :const:`None` |
| 3699 |
|
| 3700 |
An optional user ID to use when events :program:`celery events` drops its privileges (defaults to no UID change). |
| 3701 |
|
| 3702 |
.. setting:: events_gid |
| 3703 |
|
| 3704 |
``events_gid`` |
| 3705 |
~~~~~~~~~~~~~~ |
| 3706 |
|
| 3707 |
.. versionadded:: 5.4 |
| 3708 |
|
| 3709 |
Default: :const:`None` |
| 3710 |
|
| 3711 |
An optional group ID to use when :program:`celery events` daemon drops its privileges (defaults to no GID change). |
| 3712 |
|
| 3713 |
.. setting:: events_umask |
| 3714 |
|
| 3715 |
``events_umask`` |
| 3716 |
~~~~~~~~~~~~~~~~ |
| 3717 |
|
| 3718 |
.. versionadded:: 5.4 |
| 3719 |
|
| 3720 |
Default: :const:`None` |
| 3721 |
|
| 3722 |
An optional `umask` to use when :program:`celery events` creates files (log, pid...) when daemonizing. |
| 3723 |
|
| 3724 |
.. setting:: events_executable |
| 3725 |
|
| 3726 |
``events_executable`` |
| 3727 |
~~~~~~~~~~~~~~~~~~~~~ |
| 3728 |
|
| 3729 |
.. versionadded:: 5.4 |
| 3730 |
|
| 3731 |
Default: :const:`None` |
| 3732 |
|
| 3733 |
An optional `python` executable path for :program:`celery events` to use when deaemonizing (defaults to :data:`sys.executable`). |
| 3734 |
|
| 3735 |
|
| 3736 |
.. _conf-control: |
| 3737 |
|
| 3738 |
Remote Control Commands |
| 3739 |
----------------------- |
| 3740 |
|
| 3741 |
.. note:: |
| 3742 |
|
| 3743 |
To disable remote control commands see |
| 3744 |
the :setting:`worker_enable_remote_control` setting. |
| 3745 |
|
| 3746 |
.. setting:: control_queue_ttl |
| 3747 |
|
| 3748 |
``control_queue_ttl`` |
| 3749 |
~~~~~~~~~~~~~~~~~~~~~ |
| 3750 |
|
| 3751 |
Default: 300.0 |
| 3752 |
|
| 3753 |
Time in seconds, before a message in a remote control command queue |
| 3754 |
will expire. |
| 3755 |
|
| 3756 |
If using the default of 300 seconds, this means that if a remote control |
| 3757 |
command is sent and no worker picks it up within 300 seconds, the command |
| 3758 |
is discarded. |
| 3759 |
|
| 3760 |
This setting also applies to remote control reply queues. |
| 3761 |
|
| 3762 |
.. setting:: control_queue_expires |
| 3763 |
|
| 3764 |
``control_queue_expires`` |
| 3765 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3766 |
|
| 3767 |
Default: 10.0 |
| 3768 |
|
| 3769 |
Time in seconds, before an unused remote control command queue is deleted |
| 3770 |
from the broker. |
| 3771 |
|
| 3772 |
This setting also applies to remote control reply queues. |
| 3773 |
|
| 3774 |
.. setting:: control_exchange |
| 3775 |
|
| 3776 |
``control_exchange`` |
| 3777 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 3778 |
|
| 3779 |
Default: ``"celery"``. |
| 3780 |
|
| 3781 |
Name of the control command exchange. |
| 3782 |
|
| 3783 |
.. warning:: |
| 3784 |
|
| 3785 |
This option is in experimental stage, please use it with caution. |
| 3786 |
|
| 3787 |
.. _conf-logging: |
| 3788 |
|
| 3789 |
.. setting:: control_queue_durable |
| 3790 |
|
| 3791 |
``control_queue_durable`` |
| 3792 |
------------------------- |
| 3793 |
|
| 3794 |
- **Default:** ``False`` |
| 3795 |
- **Type:** ``bool`` |
| 3796 |
|
| 3797 |
If set to ``True``, the control exchange and queue will be durable — they will survive broker restarts. |
| 3798 |
|
| 3799 |
.. setting:: control_queue_exclusive |
| 3800 |
|
| 3801 |
``control_queue_exclusive`` |
| 3802 |
--------------------------- |
| 3803 |
|
| 3804 |
- **Default:** ``False`` |
| 3805 |
- **Type:** ``bool`` |
| 3806 |
|
| 3807 |
If set to ``True``, the control queue will be exclusive to a single connection. This is generally not recommended in distributed environments. |
| 3808 |
|
| 3809 |
.. warning:: |
| 3810 |
|
| 3811 |
Setting both ``control_queue_durable`` and ``control_queue_exclusive`` to ``True`` is not supported and will raise an error. |
| 3812 |
|
| 3813 |
|
| 3814 |
Logging |
| 3815 |
------- |
| 3816 |
|
| 3817 |
.. setting:: worker_hijack_root_logger |
| 3818 |
|
| 3819 |
``worker_hijack_root_logger`` |
| 3820 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3821 |
|
| 3822 |
.. versionadded:: 2.2 |
| 3823 |
|
| 3824 |
Default: Enabled by default (hijack root logger). |
| 3825 |
|
| 3826 |
By default any previously configured handlers on the root logger will be |
| 3827 |
removed. If you want to customize your own logging handlers, then you |
| 3828 |
can disable this behavior by setting |
| 3829 |
`worker_hijack_root_logger = False`. |
| 3830 |
|
| 3831 |
.. note:: |
| 3832 |
|
| 3833 |
Logging can also be customized by connecting to the |
| 3834 |
:signal:`celery.signals.setup_logging` signal. |
| 3835 |
|
| 3836 |
.. setting:: worker_log_color |
| 3837 |
|
| 3838 |
``worker_log_color`` |
| 3839 |
~~~~~~~~~~~~~~~~~~~~ |
| 3840 |
|
| 3841 |
Default: Enabled if app is logging to a terminal. |
| 3842 |
|
| 3843 |
Enables/disables colors in logging output by the Celery apps. |
| 3844 |
|
| 3845 |
.. setting:: worker_log_format |
| 3846 |
|
| 3847 |
``worker_log_format`` |
| 3848 |
~~~~~~~~~~~~~~~~~~~~~ |
| 3849 |
|
| 3850 |
Default: |
| 3851 |
|
| 3852 |
.. code-block:: text |
| 3853 |
|
| 3854 |
"[%(asctime)s: %(levelname)s/%(processName)s] %(message)s" |
| 3855 |
|
| 3856 |
The format to use for log messages. |
| 3857 |
|
| 3858 |
See the Python :mod:`logging` module for more information about log |
| 3859 |
formats. |
| 3860 |
|
| 3861 |
.. setting:: worker_task_log_format |
| 3862 |
|
| 3863 |
``worker_task_log_format`` |
| 3864 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3865 |
|
| 3866 |
Default: |
| 3867 |
|
| 3868 |
.. code-block:: text |
| 3869 |
|
| 3870 |
"[%(asctime)s: %(levelname)s/%(processName)s] |
| 3871 |
%(task_name)s[%(task_id)s]: %(message)s" |
| 3872 |
|
| 3873 |
The format to use for log messages logged in tasks. |
| 3874 |
|
| 3875 |
See the Python :mod:`logging` module for more information about log |
| 3876 |
formats. |
| 3877 |
|
| 3878 |
.. setting:: worker_redirect_stdouts |
| 3879 |
|
| 3880 |
``worker_redirect_stdouts`` |
| 3881 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3882 |
|
| 3883 |
Default: Enabled by default. |
| 3884 |
|
| 3885 |
If enabled `stdout` and `stderr` will be redirected |
| 3886 |
to the current logger. |
| 3887 |
|
| 3888 |
Used by :program:`celery worker` and :program:`celery beat`. |
| 3889 |
|
| 3890 |
.. setting:: worker_redirect_stdouts_level |
| 3891 |
|
| 3892 |
``worker_redirect_stdouts_level`` |
| 3893 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3894 |
|
| 3895 |
Default: :const:`WARNING`. |
| 3896 |
|
| 3897 |
The log level output to `stdout` and `stderr` is logged as. |
| 3898 |
Can be one of :const:`DEBUG`, :const:`INFO`, :const:`WARNING`, |
| 3899 |
:const:`ERROR`, or :const:`CRITICAL`. |
| 3900 |
|
| 3901 |
.. _conf-security: |
| 3902 |
|
| 3903 |
Security |
| 3904 |
-------- |
| 3905 |
|
| 3906 |
.. setting:: security_key |
| 3907 |
|
| 3908 |
``security_key`` |
| 3909 |
~~~~~~~~~~~~~~~~ |
| 3910 |
|
| 3911 |
Default: :const:`None`. |
| 3912 |
|
| 3913 |
.. versionadded:: 2.5 |
| 3914 |
|
| 3915 |
The relative or absolute path to a file containing the private key |
| 3916 |
used to sign messages when :ref:`message-signing` is used. |
| 3917 |
|
| 3918 |
.. setting:: security_key_password |
| 3919 |
|
| 3920 |
``security_key_password`` |
| 3921 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3922 |
|
| 3923 |
Default: :const:`None`. |
| 3924 |
|
| 3925 |
.. versionadded:: 5.3.0 |
| 3926 |
|
| 3927 |
The password used to decrypt the private key when :ref:`message-signing` |
| 3928 |
is used. |
| 3929 |
|
| 3930 |
.. setting:: security_certificate |
| 3931 |
|
| 3932 |
``security_certificate`` |
| 3933 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3934 |
|
| 3935 |
Default: :const:`None`. |
| 3936 |
|
| 3937 |
.. versionadded:: 2.5 |
| 3938 |
|
| 3939 |
The relative or absolute path to an X.509 certificate file |
| 3940 |
used to sign messages when :ref:`message-signing` is used. |
| 3941 |
|
| 3942 |
.. setting:: security_cert_store |
| 3943 |
|
| 3944 |
``security_cert_store`` |
| 3945 |
~~~~~~~~~~~~~~~~~~~~~~~ |
| 3946 |
|
| 3947 |
Default: :const:`None`. |
| 3948 |
|
| 3949 |
.. versionadded:: 2.5 |
| 3950 |
|
| 3951 |
The directory containing X.509 certificates used for |
| 3952 |
:ref:`message-signing`. Can be a glob with wild-cards, |
| 3953 |
(for example :file:`/etc/certs/*.pem`). |
| 3954 |
|
| 3955 |
.. setting:: security_digest |
| 3956 |
|
| 3957 |
``security_digest`` |
| 3958 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3959 |
|
| 3960 |
Default: :const:`sha256`. |
| 3961 |
|
| 3962 |
.. versionadded:: 4.3 |
| 3963 |
|
| 3964 |
A cryptography digest used to sign messages |
| 3965 |
when :ref:`message-signing` is used. |
| 3966 |
https://cryptography.io/en/latest/hazmat/primitives/cryptographic-hashes/#module-cryptography.hazmat.primitives.hashes |
| 3967 |
|
| 3968 |
.. _conf-custom-components: |
| 3969 |
|
| 3970 |
Custom Component Classes (advanced) |
| 3971 |
----------------------------------- |
| 3972 |
|
| 3973 |
.. setting:: worker_pool |
| 3974 |
|
| 3975 |
``worker_pool`` |
| 3976 |
~~~~~~~~~~~~~~~ |
| 3977 |
|
| 3978 |
Default: ``"prefork"`` (``celery.concurrency.prefork:TaskPool``). |
| 3979 |
|
| 3980 |
Name of the pool class used by the worker. |
| 3981 |
|
| 3982 |
.. admonition:: Eventlet/Gevent |
| 3983 |
|
| 3984 |
Never use this option to select the eventlet or gevent pool. |
| 3985 |
You must use the :option:`-P <celery worker -P>` option to |
| 3986 |
:program:`celery worker` instead, to ensure the monkey patches |
| 3987 |
aren't applied too late, causing things to break in strange ways. |
| 3988 |
|
| 3989 |
.. setting:: worker_pool_restarts |
| 3990 |
|
| 3991 |
``worker_pool_restarts`` |
| 3992 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3993 |
|
| 3994 |
Default: Disabled by default. |
| 3995 |
|
| 3996 |
If enabled the worker pool can be restarted using the |
| 3997 |
:control:`pool_restart` remote control command. |
| 3998 |
|
| 3999 |
.. setting:: worker_autoscaler |
| 4000 |
|
| 4001 |
``worker_autoscaler`` |
| 4002 |
~~~~~~~~~~~~~~~~~~~~~ |
| 4003 |
|
| 4004 |
.. versionadded:: 2.2 |
| 4005 |
|
| 4006 |
Default: ``"celery.worker.autoscale:Autoscaler"``. |
| 4007 |
|
| 4008 |
Name of the autoscaler class to use. |
| 4009 |
|
| 4010 |
.. setting:: worker_consumer |
| 4011 |
|
| 4012 |
``worker_consumer`` |
| 4013 |
~~~~~~~~~~~~~~~~~~~ |
| 4014 |
|
| 4015 |
Default: ``"celery.worker.consumer:Consumer"``. |
| 4016 |
|
| 4017 |
Name of the consumer class used by the worker. |
| 4018 |
|
| 4019 |
.. setting:: worker_timer |
| 4020 |
|
| 4021 |
``worker_timer`` |
| 4022 |
~~~~~~~~~~~~~~~~ |
| 4023 |
|
| 4024 |
Default: ``"kombu.asynchronous.hub.timer:Timer"``. |
| 4025 |
|
| 4026 |
Name of the ETA scheduler class used by the worker. |
| 4027 |
Default is or set by the pool implementation. |
| 4028 |
|
| 4029 |
.. setting:: worker_logfile |
| 4030 |
|
| 4031 |
``worker_logfile`` |
| 4032 |
~~~~~~~~~~~~~~~~~~ |
| 4033 |
|
| 4034 |
.. versionadded:: 5.4 |
| 4035 |
|
| 4036 |
Default: :const:`None` |
| 4037 |
|
| 4038 |
An optional file path for :program:`celery worker` to log into (defaults to `stdout`). |
| 4039 |
|
| 4040 |
.. setting:: worker_pidfile |
| 4041 |
|
| 4042 |
``worker_pidfile`` |
| 4043 |
~~~~~~~~~~~~~~~~~~ |
| 4044 |
|
| 4045 |
.. versionadded:: 5.4 |
| 4046 |
|
| 4047 |
Default: :const:`None` |
| 4048 |
|
| 4049 |
An optional file path for :program:`celery worker` to create/store its PID file (defaults to no PID file created). |
| 4050 |
|
| 4051 |
.. setting:: worker_uid |
| 4052 |
|
| 4053 |
``worker_uid`` |
| 4054 |
~~~~~~~~~~~~~~ |
| 4055 |
|
| 4056 |
.. versionadded:: 5.4 |
| 4057 |
|
| 4058 |
Default: :const:`None` |
| 4059 |
|
| 4060 |
An optional user ID to use when :program:`celery worker` daemon drops its privileges (defaults to no UID change). |
| 4061 |
|
| 4062 |
.. setting:: worker_gid |
| 4063 |
|
| 4064 |
``worker_gid`` |
| 4065 |
~~~~~~~~~~~~~~ |
| 4066 |
|
| 4067 |
.. versionadded:: 5.4 |
| 4068 |
|
| 4069 |
Default: :const:`None` |
| 4070 |
|
| 4071 |
An optional group ID to use when :program:`celery worker` daemon drops its privileges (defaults to no GID change). |
| 4072 |
|
| 4073 |
.. setting:: worker_umask |
| 4074 |
|
| 4075 |
``worker_umask`` |
| 4076 |
~~~~~~~~~~~~~~~~ |
| 4077 |
|
| 4078 |
.. versionadded:: 5.4 |
| 4079 |
|
| 4080 |
Default: :const:`None` |
| 4081 |
|
| 4082 |
An optional `umask` to use when :program:`celery worker` creates files (log, pid...) when daemonizing. |
| 4083 |
|
| 4084 |
.. setting:: worker_executable |
| 4085 |
|
| 4086 |
``worker_executable`` |
| 4087 |
~~~~~~~~~~~~~~~~~~~~~ |
| 4088 |
|
| 4089 |
.. versionadded:: 5.4 |
| 4090 |
|
| 4091 |
Default: :const:`None` |
| 4092 |
|
| 4093 |
An optional `python` executable path for :program:`celery worker` to use when deaemonizing (defaults to :data:`sys.executable`). |
| 4094 |
|
| 4095 |
.. _conf-celerybeat: |
| 4096 |
|
| 4097 |
Beat Settings (:program:`celery beat`) |
| 4098 |
-------------------------------------- |
| 4099 |
|
| 4100 |
.. setting:: beat_schedule |
| 4101 |
|
| 4102 |
``beat_schedule`` |
| 4103 |
~~~~~~~~~~~~~~~~~ |
| 4104 |
|
| 4105 |
Default: ``{}`` (empty mapping). |
| 4106 |
|
| 4107 |
The periodic task schedule used by :mod:`~celery.bin.beat`. |
| 4108 |
See :ref:`beat-entries`. |
| 4109 |
|
| 4110 |
.. setting:: beat_scheduler |
| 4111 |
|
| 4112 |
``beat_scheduler`` |
| 4113 |
~~~~~~~~~~~~~~~~~~ |
| 4114 |
|
| 4115 |
Default: ``"celery.beat:PersistentScheduler"``. |
| 4116 |
|
| 4117 |
The default scheduler class. May be set to |
| 4118 |
``"django_celery_beat.schedulers:DatabaseScheduler"`` for instance, |
| 4119 |
if used alongside :pypi:`django-celery-beat` extension. |
| 4120 |
|
| 4121 |
Can also be set via the :option:`celery beat -S` argument. |
| 4122 |
|
| 4123 |
.. setting:: beat_schedule_filename |
| 4124 |
|
| 4125 |
``beat_schedule_filename`` |
| 4126 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4127 |
|
| 4128 |
Default: ``"celerybeat-schedule"``. |
| 4129 |
|
| 4130 |
Name of the file used by `PersistentScheduler` to store the last run times |
| 4131 |
of periodic tasks. Can be a relative or absolute path, but be aware that the |
| 4132 |
suffix `.db` may be appended to the file name (depending on Python version). |
| 4133 |
|
| 4134 |
Can also be set via the :option:`celery beat --schedule` argument. |
| 4135 |
|
| 4136 |
.. setting:: beat_sync_every |
| 4137 |
|
| 4138 |
``beat_sync_every`` |
| 4139 |
~~~~~~~~~~~~~~~~~~~ |
| 4140 |
|
| 4141 |
Default: 0. |
| 4142 |
|
| 4143 |
The number of periodic tasks that can be called before another database sync |
| 4144 |
is issued. |
| 4145 |
A value of 0 (default) means sync based on timing - default of 3 minutes as determined by |
| 4146 |
scheduler.sync_every. If set to 1, beat will call sync after every task |
| 4147 |
message sent. |
| 4148 |
|
| 4149 |
.. setting:: beat_max_loop_interval |
| 4150 |
|
| 4151 |
``beat_max_loop_interval`` |
| 4152 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4153 |
|
| 4154 |
Default: 0. |
| 4155 |
|
| 4156 |
The maximum number of seconds :mod:`~celery.bin.beat` can sleep |
| 4157 |
between checking the schedule. |
| 4158 |
|
| 4159 |
The default for this value is scheduler specific. |
| 4160 |
For the default Celery beat scheduler the value is 300 (5 minutes), |
| 4161 |
but for the :pypi:`django-celery-beat` database scheduler it's 5 seconds |
| 4162 |
because the schedule may be changed externally, and so it must take |
| 4163 |
changes to the schedule into account. |
| 4164 |
|
| 4165 |
Also when running Celery beat embedded (:option:`-B <celery worker -B>`) |
| 4166 |
on Jython as a thread the max interval is overridden and set to 1 so |
| 4167 |
that it's possible to shut down in a timely manner. |
| 4168 |
|
| 4169 |
.. setting:: beat_cron_starting_deadline |
| 4170 |
|
| 4171 |
``beat_cron_starting_deadline`` |
| 4172 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4173 |
|
| 4174 |
.. versionadded:: 5.3 |
| 4175 |
|
| 4176 |
Default: None. |
| 4177 |
|
| 4178 |
When using cron, the number of seconds :mod:`~celery.bin.beat` can look back |
| 4179 |
when deciding whether a cron schedule is due. When set to `None`, cronjobs that |
| 4180 |
are past due will always run immediately. |
| 4181 |
|
| 4182 |
.. warning:: |
| 4183 |
|
| 4184 |
Setting this higher than 3600 (1 hour) is highly discouraged. |
| 4185 |
|
| 4186 |
.. setting:: beat_logfile |
| 4187 |
|
| 4188 |
``beat_logfile`` |
| 4189 |
~~~~~~~~~~~~~~~~ |
| 4190 |
|
| 4191 |
.. versionadded:: 5.4 |
| 4192 |
|
| 4193 |
Default: :const:`None` |
| 4194 |
|
| 4195 |
An optional file path for :program:`celery beat` to log into (defaults to `stdout`). |
| 4196 |
|
| 4197 |
.. setting:: beat_pidfile |
| 4198 |
|
| 4199 |
``beat_pidfile`` |
| 4200 |
~~~~~~~~~~~~~~~~ |
| 4201 |
|
| 4202 |
.. versionadded:: 5.4 |
| 4203 |
|
| 4204 |
Default: :const:`None` |
| 4205 |
|
| 4206 |
An optional file path for :program:`celery beat` to create/store it PID file (defaults to no PID file created). |
| 4207 |
|
| 4208 |
.. setting:: beat_uid |
| 4209 |
|
| 4210 |
``beat_uid`` |
| 4211 |
~~~~~~~~~~~~ |
| 4212 |
|
| 4213 |
.. versionadded:: 5.4 |
| 4214 |
|
| 4215 |
Default: :const:`None` |
| 4216 |
|
| 4217 |
An optional user ID to use when beat :program:`celery beat` drops its privileges (defaults to no UID change). |
| 4218 |
|
| 4219 |
.. setting:: beat_gid |
| 4220 |
|
| 4221 |
``beat_gid`` |
| 4222 |
~~~~~~~~~~~~ |
| 4223 |
|
| 4224 |
.. versionadded:: 5.4 |
| 4225 |
|
| 4226 |
Default: :const:`None` |
| 4227 |
|
| 4228 |
An optional group ID to use when :program:`celery beat` daemon drops its privileges (defaults to no GID change). |
| 4229 |
|
| 4230 |
.. setting:: beat_umask |
| 4231 |
|
| 4232 |
``beat_umask`` |
| 4233 |
~~~~~~~~~~~~~~ |
| 4234 |
|
| 4235 |
.. versionadded:: 5.4 |
| 4236 |
|
| 4237 |
Default: :const:`None` |
| 4238 |
|
| 4239 |
An optional `umask` to use when :program:`celery beat` creates files (log, pid...) when daemonizing. |
| 4240 |
|
| 4241 |
.. setting:: beat_executable |
| 4242 |
|
| 4243 |
``beat_executable`` |
| 4244 |
~~~~~~~~~~~~~~~~~~~ |
| 4245 |
|
| 4246 |
.. versionadded:: 5.4 |
| 4247 |
|
| 4248 |
Default: :const:`None` |
| 4249 |
|
| 4250 |
An optional `python` executable path for :program:`celery beat` to use when deaemonizing (defaults to :data:`sys.executable`). |