From c202bc0a79ad3a7d83f31bfd01209f05e4f92e6d Mon Sep 17 00:00:00 2001 From: Ray Wang <134452344+ray-oxd@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:08:39 -0800 Subject: [PATCH] DBC22-1404: added huey locks to tasks (#222) --- src/backend/apps/feed/tasks.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/backend/apps/feed/tasks.py b/src/backend/apps/feed/tasks.py index f729e7a24..451e12242 100644 --- a/src/backend/apps/feed/tasks.py +++ b/src/backend/apps/feed/tasks.py @@ -3,29 +3,37 @@ from apps.webcam.tasks import populate_all_webcam_data, update_all_webcam_data from django.core.management import call_command from huey import crontab -from huey.contrib.djhuey import db_periodic_task +from huey.contrib.djhuey import HUEY as HUEY_INSTANCE +from huey.contrib.djhuey import db_periodic_task, lock_task -@db_periodic_task(crontab(hour="*/6")) +@db_periodic_task(crontab(hour="*/6"), retries=6, retry_delay=300, priority=20) +@lock_task('populate-cameras') def populate_webcam_task(): populate_all_webcam_data() -@db_periodic_task(crontab(minute="*/1")) +@db_periodic_task(crontab(minute="*/1"), priority=10) +@lock_task('update-cameras') def update_camera_task(): - update_all_webcam_data() + # Do not run when populate task is running + if not HUEY_INSTANCE.is_locked('populate-cameras'): + update_all_webcam_data() @db_periodic_task(crontab(minute="*/5")) +@lock_task('populate-events') def populate_event_task(): populate_all_event_data() @db_periodic_task(crontab(hour="*/24")) +@lock_task('populate-ferries') def populate_ferry_task(): populate_all_ferry_data() @db_periodic_task(crontab(minute="*/1")) +@lock_task('publish-scheduled-cms-objs') def publish_scheduled(): call_command('publish_scheduled')