40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import time
|
|
from datetime import datetime, date
|
|
from logging_config import get_logger
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
class Scheduler:
|
|
def __init__(self, processor, config):
|
|
self.processor = processor
|
|
self.config = config
|
|
self.last_cycle_date = None
|
|
self.cycle_no = 0
|
|
|
|
def _update_cycle(self):
|
|
today = date.today()
|
|
if self.last_cycle_date != today:
|
|
self.cycle_no = 1
|
|
self.last_cycle_date = today
|
|
else:
|
|
self.cycle_no += 1
|
|
|
|
def run(self):
|
|
logger.info("NEFT OUTWARD Scheduler started")
|
|
|
|
while True:
|
|
try:
|
|
self._update_cycle()
|
|
insert_count = self.processor.process()
|
|
|
|
if insert_count > 0:
|
|
logger.info("Calling neft_api_txn_post procedure...")
|
|
if self.processor.repo.call_neft_api_txn_post():
|
|
logger.info("Transaction post-processing completed successfully")
|
|
else:
|
|
logger.error("Transaction post-processing failed")
|
|
|
|
except Exception:
|
|
logger.exception("Scheduler cycle failed")
|
|
|
|
time.sleep(self.config.poll_interval_minutes * 60) |