Commit 174ccfb1 authored by Akshay G's avatar Akshay G

date-time

parent 5576782f
......@@ -29,16 +29,16 @@ def create_db_obj():
def insert_records(msserver_obj, data):
# METHOD 1: Hardcode zones:
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('Asia/Kolkata')
print(to_zone)
utc = datetime.utcnow()
utc = utc.replace(tzinfo=from_zone)
# Convert time zone
central = utc.astimezone(to_zone)
print(central)
# from_zone = tz.gettz('UTC')
# to_zone = tz.gettz('Asia/Kolkata')
# print(to_zone)
# utc = datetime.utcnow()
# utc = utc.replace(tzinfo=from_zone)
# # Convert time zone
# central = utc.astimezone(to_zone)
# print(central)
data = {
"job_run_date": central,
"job_run_date": datetime.now(),
"auto_update": 1,
"shift_hours": 8,
"group_event_period_seconds": 300,
......@@ -47,7 +47,7 @@ def insert_records(msserver_obj, data):
}
x = msserver_obj.insert_records(data)
print(x)
# print(x)
return x
......
......@@ -17,7 +17,7 @@ MYSQL_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'msserver'
class configurations(Base):
__tablename__ = MYSQL_CONFIG['test_config']
__tablename__ = MYSQL_CONFIG['config_table']
# id = sa.Column(sa.VARCHAR(10), nullable=False, primary_key=True)
id = sa.Column(sa.Integer, primary_key=True)
job_run_date = sa.Column(sa.DATETIME, nullable=False)
......@@ -65,24 +65,27 @@ class CRON:
def insert_records(self, data):
res = self.session.query(configurations).count()
print(res)
# print(res)
logger.info("total records in config {}".format(res))
if res == 0:
self.session.add(self.insert(data))
self.session.commit()
else:
data = self.getConfig()
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('Asia/Kolkata')
print(to_zone)
utc = datetime.utcnow()
utc = utc.replace(tzinfo=from_zone)
# Convert time zone
localtimenow = utc.astimezone(to_zone)
print(data)
check = (data['job_run_date'] + timedelta(minutes=data['job_interval_minutes'])).astimezone(to_zone)
print(check,localtimenow)
# from_zone = tz.gettz('UTC')
# to_zone = tz.gettz('Asia/Kolkata')
# print(to_zone)
# utc = datetime.utcnow()
# utc = utc.replace(tzinfo=from_zone)
# # Convert time zone
# localtimenow = utc.astimezone(to_zone)
localtimenow = datetime.now()
# print(data)
check = (data['job_run_date'] + timedelta(minutes=data['job_interval_minutes']))
logger.info("Previous job run time and job interval are {}, {}".format(data['job_run_date'],data['job_interval_minutes']))
# print(check,localtimenow)
if data['auto_update'] == 1 and check < localtimenow:
print(data['job_run_date'], data['job_interval_minutes'])
# print(data['job_run_date'], data['job_interval_minutes'])
data['job_run_date'] = localtimenow
self.session.add(self.insert(data))
self.session.commit()
......@@ -91,11 +94,11 @@ class CRON:
def insertConfigTime(self, job_date):
data = {
"job_run_date": job_date,
"auto_update": 1,
"shift_hours": 8,
"group_event_period_seconds": 300,
"over_time_hours": 3,
"job_interval_minutes": 15
"auto_update": MYSQL_CONFIG['auto_update'],
"shift_hours": MYSQL_CONFIG['shift_hours'],
"group_event_period_seconds": MYSQL_CONFIG['group_event_period_seconds'],
"over_time_hours": MYSQL_CONFIG['over_time_hours'],
"job_interval_minutes": MYSQL_CONFIG['job_interval_minutes']
}
self.session.add(self.insert(data))
self.session.commit()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment