|
306 | 306 | REDIS_HOST = os.environ.get('REDIS_HOST', 'redis') |
307 | 307 | REDIS_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}" |
308 | 308 |
|
| 309 | +REDIS_SENTINELS = os.environ.get('REDIS_SENTINELS', None) |
| 310 | +REDIS_SENTINELS_MASTER = os.environ.get('REDIS_SENTINELS_MASTER', 'default') |
| 311 | +REDIS_SENTINELS_LIST = [] |
| 312 | + |
309 | 313 | # django cache |
310 | 314 | if ENV and ENV not in ['ci']: |
| 315 | + OPTIONS = {} |
| 316 | + if REDIS_SENTINELS: |
| 317 | + for REDIS_SENTINEL in REDIS_SENTINELS.split(','): |
| 318 | + SENTINEL = REDIS_SENTINEL.split(':') |
| 319 | + REDIS_SENTINELS_LIST.append((SENTINEL[0], int(SENTINEL[1]))) |
| 320 | + OPTIONS.update({ |
| 321 | + 'CLIENT_CLASS': 'django_redis.client.SentinelClient', |
| 322 | + 'SENTINELS': REDIS_SENTINELS_LIST |
| 323 | + }) |
| 324 | + |
311 | 325 | CACHES = { |
312 | 326 | 'default': { |
313 | | - 'BACKEND': 'django.core.cache.backends.redis.RedisCache', |
| 327 | + 'BACKEND': 'django_redis.cache.RedisCache', |
314 | 328 | 'LOCATION': REDIS_URL, |
| 329 | + 'OPTIONS': OPTIONS |
315 | 330 | } |
316 | 331 | } |
317 | 332 |
|
|
337 | 352 | 'core.common.tasks.populate_indexes': {'queue': 'indexing'}, |
338 | 353 | 'core.common.tasks.rebuild_indexes': {'queue': 'indexing'} |
339 | 354 | } |
340 | | -CELERY_RESULT_BACKEND = f'redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}' |
341 | | -CELERY_RESULT_EXTENDED = True |
| 355 | + |
| 356 | +CELERY_BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 259200} # 72 hours, the longest ETA |
342 | 357 | CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS = { |
343 | 358 | 'retry_policy': { |
344 | 359 | 'timeout': 10.0 |
345 | 360 | } |
346 | 361 | } |
| 362 | + |
| 363 | +if REDIS_SENTINELS: |
| 364 | + CELERY_RESULT_BACKEND = '' |
| 365 | + for REDIS_SENTINEL in REDIS_SENTINELS.split(','): |
| 366 | + CELERY_RESULT_BACKEND = CELERY_RESULT_BACKEND + f'sentinel://{REDIS_SENTINEL}/0;' |
| 367 | + CELERY_BROKER_TRANSPORT_OPTIONS.update({'master_name': REDIS_SENTINELS_MASTER}) |
| 368 | + CELERY_RESULT_BACKEND_TRANSPORT_OPTIONS.update({'master_name': REDIS_SENTINELS_MASTER}) |
| 369 | +else: |
| 370 | + CELERY_RESULT_BACKEND = f'redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}' |
| 371 | + |
| 372 | +CELERY_RESULT_EXTENDED = True |
347 | 373 | CELERY_RESULT_EXPIRES = 259200 # 72 hours |
348 | 374 | CELERY_BROKER_URL = CELERY_RESULT_BACKEND |
349 | 375 | CELERY_BROKER_POOL_LIMIT = 50 # should be adjusted considering the number of threads |
350 | 376 | CELERY_BROKER_CONNECTION_TIMEOUT = 10.0 |
351 | | -CELERY_BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 259200} # 72 hours, the lon |
352 | 377 | CELERY_ACCEPT_CONTENT = ['application/json'] |
353 | | -CELERY_ONCE = { |
354 | | - 'backend': 'celery_once.backends.Redis', |
355 | | - 'settings': { |
356 | | - 'url': CELERY_RESULT_BACKEND, |
| 378 | +if REDIS_SENTINELS: |
| 379 | + CELERY_ONCE = { |
| 380 | + 'backend': 'core.common.backends.QueueOnceRedisSentinelBackend', |
| 381 | + 'settings': { |
| 382 | + 'sentinels': REDIS_SENTINELS_LIST, |
| 383 | + 'sentinels_master': REDIS_SENTINELS_MASTER |
| 384 | + } |
| 385 | + } |
| 386 | +else: |
| 387 | + CELERY_ONCE = { |
| 388 | + 'backend': 'celery_once.backends.Redis', |
| 389 | + 'settings': { |
| 390 | + 'url': CELERY_RESULT_BACKEND, |
| 391 | + } |
357 | 392 | } |
358 | | -} |
359 | 393 | CELERYBEAT_SCHEDULE = { |
360 | 394 | 'healthcheck-every-minute': { |
361 | 395 | 'task': 'core.common.tasks.beat_healthcheck', |
|
0 commit comments