fix: use rq schedule cron instead of schedule
Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
parent
e0c0e3bf2b
commit
b0b5c533af
2 changed files with 4 additions and 22 deletions
|
|
@ -18,7 +18,7 @@ class AppConfig(AppConfig):
|
||||||
name = 'app'
|
name = 'app'
|
||||||
|
|
||||||
def ready(self):
|
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
|
# This is necessary to prevent dupes
|
||||||
scheduler = django_rq.get_scheduler('default')
|
scheduler = django_rq.get_scheduler('default')
|
||||||
|
|
@ -26,11 +26,10 @@ class AppConfig(AppConfig):
|
||||||
for job in scheduler.get_jobs():
|
for job in scheduler.get_jobs():
|
||||||
job.delete()
|
job.delete()
|
||||||
# Schedule jobs here as required
|
# Schedule jobs here as required
|
||||||
next_date_time = get_next_update_datetime()
|
scheduler.cron(
|
||||||
scheduler.schedule(
|
"0 6 * * *",
|
||||||
scheduled_time=next_date_time, # UTC
|
|
||||||
func=populate_bhav_copy_data,
|
func=populate_bhav_copy_data,
|
||||||
interval=86400,
|
repeat=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue