From b0b5c533af753630cf7e6fc3973f7cc8beaeba33 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Thu, 11 Feb 2021 17:49:04 +0530 Subject: [PATCH] fix: use rq schedule cron instead of schedule Signed-off-by: Ameya Shenoy --- backend/app/apps.py | 9 ++++----- backend/app/utils.py | 17 ----------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/backend/app/apps.py b/backend/app/apps.py index 9cace7b..9e78197 100644 --- a/backend/app/apps.py +++ b/backend/app/apps.py @@ -18,7 +18,7 @@ class AppConfig(AppConfig): name = 'app' def ready(self): - from app.utils import populate_bhav_copy_data, get_next_update_datetime + from app.utils import populate_bhav_copy_data # This is necessary to prevent dupes scheduler = django_rq.get_scheduler('default') @@ -26,11 +26,10 @@ class AppConfig(AppConfig): for job in scheduler.get_jobs(): job.delete() # Schedule jobs here as required - next_date_time = get_next_update_datetime() - scheduler.schedule( - scheduled_time=next_date_time, # UTC + scheduler.cron( + "0 6 * * *", func=populate_bhav_copy_data, - interval=86400, + repeat=None, ) diff --git a/backend/app/utils.py b/backend/app/utils.py index 148b947..486b883 100644 --- a/backend/app/utils.py +++ b/backend/app/utils.py @@ -95,20 +95,3 @@ def populate_bhav_copy_data(): ) -def get_next_update_datetime(date=None): - schedule_hour = 12 # UTC - schedule_minute = 30 - next_date_time = now = datetime.datetime.now() - if date: - next_date_time = now = date - if now.hour >= schedule_hour and now.minute >= schedule_minute: - next_date_time = now + datetime.timedelta(days=1) - next_date_time = next_date_time.replace( - hour=schedule_hour, - minute=schedule_minute, - second=0, - microsecond=0 - ) - return next_date_time - -