I have a Django v5.0.6 application (Python v3.12) in which I integrated Celery v5.4 to run asynchronous tasks, such as generating images via the OpenAI API, which takes about 2 minutes.
The entire setup is deployed on Heroku. Here is the content of my Procfile
:
web: gunicorn mngrs_backend.wsgi --timeout 600
worker: celery -A mngrs_backend worker -l info --time-limit=7200
However, after 30 seconds, I get the following error in the logs:
I am looking to increase the delay to avoid a timeout.
Here are the attempts I made without success:
-
Added
--timeout 600
in the gunicorn command in theProcfile
-
Added
--time-limit=7200
in the celery command in theProcfile
-
Added a timeout to the API request:
requests.post(url, json=payload, headers=headers, timeout=600)
-
Modified the configuration in celery.py
app = Celery("mngrs_backend") app.conf.update( task_soft_time_limit=60 * 10, task_time_limit=60 * 12, )
-
Added in the project
settings
:CELERY_BROKER_TRANSPORT_OPTIONS = { "visibility_timeout": 60 * 60 * 2, # 2 hours }
Locally with Celery, I do not have any timeout issues. I contacted Heroku support, but they told me the problem is with my Celery configuration.
Does anyone have a solution?