feat: schedule job in case of failure

Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
Ameya Shenoy 2021-02-11 18:06:12 +05:30
parent b0b5c533af
commit 61245829e1
Signed by: codingcoffee
GPG key ID: F7D58AAC5DACF8D3
2 changed files with 52 additions and 48 deletions

View file

@ -3,15 +3,10 @@
"""Initializer and scheduling done here."""
# standard imports
import datetime
import logging
# third-party imports
import django_rq
from django.apps import AppConfig
from django_rq.management.commands import rqscheduler
class AppConfig(AppConfig):

View file

@ -11,6 +11,7 @@ from io import BytesIO, TextIOWrapper
from zipfile import ZipFile
# third-party imports
import django_rq
import requests
from django_redis import get_redis_connection
@ -49,6 +50,7 @@ def fetch_bhav_copy_equity_data(curr_date=None):
@transaction.atomic
def populate_bhav_copy_data():
"""Populate DB with Bhav Copy data."""
try:
pipe = cache.pipeline()
data = fetch_bhav_copy_equity_data()
del data[0] # delete title row
@ -93,5 +95,12 @@ def populate_bhav_copy_data():
net_turnov=float(stock[12]),
tdcloindi=stock[13],
)
except:
# potential code for alerting if needed goes here
# Repeat job after 10 mins if fails at 6 pm
scheduler = django_rq.get_scheduler('default')
scheduler.schedule(
scheduled_time=datetime.datetime.now()+datetime.timedelta(minutes=10),
func=populate_bhav_copy_data,
)