feat: schedule job in case of failure
Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
parent
b0b5c533af
commit
61245829e1
2 changed files with 52 additions and 48 deletions
|
|
@ -3,15 +3,10 @@
|
||||||
|
|
||||||
"""Initializer and scheduling done here."""
|
"""Initializer and scheduling done here."""
|
||||||
|
|
||||||
# standard imports
|
|
||||||
import datetime
|
|
||||||
import logging
|
|
||||||
|
|
||||||
# third-party imports
|
# third-party imports
|
||||||
import django_rq
|
import django_rq
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django_rq.management.commands import rqscheduler
|
|
||||||
|
|
||||||
|
|
||||||
class AppConfig(AppConfig):
|
class AppConfig(AppConfig):
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ from io import BytesIO, TextIOWrapper
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
# third-party imports
|
# third-party imports
|
||||||
|
import django_rq
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from django_redis import get_redis_connection
|
from django_redis import get_redis_connection
|
||||||
|
|
@ -49,6 +50,7 @@ def fetch_bhav_copy_equity_data(curr_date=None):
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def populate_bhav_copy_data():
|
def populate_bhav_copy_data():
|
||||||
"""Populate DB with Bhav Copy data."""
|
"""Populate DB with Bhav Copy data."""
|
||||||
|
try:
|
||||||
pipe = cache.pipeline()
|
pipe = cache.pipeline()
|
||||||
data = fetch_bhav_copy_equity_data()
|
data = fetch_bhav_copy_equity_data()
|
||||||
del data[0] # delete title row
|
del data[0] # delete title row
|
||||||
|
|
@ -93,5 +95,12 @@ def populate_bhav_copy_data():
|
||||||
net_turnov=float(stock[12]),
|
net_turnov=float(stock[12]),
|
||||||
tdcloindi=stock[13],
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue