3

When running django celery tasks, i see that my task re execute after every hour, maybe by default visibility_timeout setting, so i try to change visibility_timeout = 120 for re execute task every 120 seconds in celery.py config like this.

app.config_from_object('django.conf:settings')
installed_apps = [app_config.name for app_config in apps.get_app_configs()]
app.conf.broker_transport_options = {'visibility_timeout': 120}
app.autodiscover_tasks(lambda: installed_apps, force=True)

But it doesn't work, what is the correct way to change visibility_timeout? I run my task from script running_celery_task.py with command: python manage.py shell < running_celery_task.py.

Here is running_celery_task.py

from project.app.tasks import my_task
my_task.delay()
Thong Nguyen
  • 405
  • 1
  • 4
  • 10
  • what are you trying achieve with setting visibility_timeout so low – iklinac Apr 04 '17 at 19:59
  • @iklinac In the example above, I just wanna test if visibility_timeout working. But in reality, i want task only execute one time when it start, not repeat after every one hour. – Thong Nguyen Apr 05 '17 at 04:17
  • Does your task finish after you execute it – iklinac Apr 05 '17 at 04:56
  • No, my task read a file line by line consecutive so it did't not have return, just waiting to read the next line appended to file. But celery make my task re execute so it again read file from begining. – Thong Nguyen Apr 05 '17 at 06:25
  • Same issue, still did not find any realated solution. I am using celery with rabitmq. – codemastermind Jul 26 '22 at 03:19

0 Answers0