fix: use rq schedule cron instead of schedule

Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
Ameya Shenoy 2021-02-11 17:49:04 +05:30
parent e0c0e3bf2b
commit b0b5c533af
Signed by: codingcoffee
GPG key ID: F7D58AAC5DACF8D3
2 changed files with 4 additions and 22 deletions

View file

@ -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,
)

View file

@ -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