Skip to content

Commit

Permalink
feat(celery): Add configurable broker visibility timeout setting (#6246)
Browse files Browse the repository at this point in the history
Co-authored-by: Víctor Fernández Poyatos <[email protected]>
  • Loading branch information
prowler-bot and vicferpoy authored Dec 18, 2024
1 parent 29dad4e commit 5d41c6a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ jQIDAQAB
-----END PUBLIC KEY-----"
# openssl rand -base64 32
DJANGO_SECRETS_ENCRYPTION_KEY="oE/ltOhp/n1TdbHjVmzcjDPLcLA41CVI/4Rk+UB5ESc="
DJANGO_BROKER_VISIBILITY_TIMEOUT=86400
1 change: 1 addition & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DJANGO_SECRETS_ENCRYPTION_KEY=""
# Decide whether to allow Django manage database table partitions
DJANGO_MANAGE_DB_PARTITIONS=[True|False]
DJANGO_CELERY_DEADLOCK_ATTEMPTS=5
DJANGO_BROKER_VISIBILITY_TIMEOUT=86400

# PostgreSQL settings
# If running django and celery on host, use 'localhost', else use 'postgres-db'
Expand Down
11 changes: 11 additions & 0 deletions api/src/backend/config/celery.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
from celery import Celery, Task
from config.env import env

BROKER_VISIBILITY_TIMEOUT = env.int("DJANGO_BROKER_VISIBILITY_TIMEOUT", default=86400)

celery_app = Celery("tasks")

celery_app.config_from_object("django.conf:settings", namespace="CELERY")
celery_app.conf.update(result_extended=True, result_expires=None)

celery_app.conf.broker_transport_options = {
"visibility_timeout": BROKER_VISIBILITY_TIMEOUT
}
celery_app.conf.result_backend_transport_options = {
"visibility_timeout": BROKER_VISIBILITY_TIMEOUT
}
celery_app.conf.visibility_timeout = BROKER_VISIBILITY_TIMEOUT

celery_app.autodiscover_tasks(["api"])


Expand Down

0 comments on commit 5d41c6a

Please sign in to comment.