Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
msserver_cron_job
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dasharatha.vamshi
msserver_cron_job
Commits
174ccfb1
Commit
174ccfb1
authored
Jul 28, 2020
by
Akshay G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
date-time
parent
5576782f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
28 deletions
+31
-28
cron-app.py
cron-app.py
+10
-10
scripts/cron_job.py
scripts/cron_job.py
+21
-18
No files found.
cron-app.py
View file @
174ccfb1
...
@@ -29,16 +29,16 @@ def create_db_obj():
...
@@ -29,16 +29,16 @@ def create_db_obj():
def
insert_records
(
msserver_obj
,
data
):
def
insert_records
(
msserver_obj
,
data
):
# METHOD 1: Hardcode zones:
# METHOD 1: Hardcode zones:
from_zone
=
tz
.
gettz
(
'UTC'
)
#
from_zone = tz.gettz('UTC')
to_zone
=
tz
.
gettz
(
'Asia/Kolkata'
)
#
to_zone = tz.gettz('Asia/Kolkata')
print
(
to_zone
)
#
print(to_zone)
utc
=
datetime
.
utcnow
()
#
utc = datetime.utcnow()
utc
=
utc
.
replace
(
tzinfo
=
from_zone
)
#
utc = utc.replace(tzinfo=from_zone)
# Convert time zone
#
#
Convert time zone
central
=
utc
.
astimezone
(
to_zone
)
#
central = utc.astimezone(to_zone)
print
(
central
)
#
print(central)
data
=
{
data
=
{
"job_run_date"
:
central
,
"job_run_date"
:
datetime
.
now
()
,
"auto_update"
:
1
,
"auto_update"
:
1
,
"shift_hours"
:
8
,
"shift_hours"
:
8
,
"group_event_period_seconds"
:
300
,
"group_event_period_seconds"
:
300
,
...
@@ -47,7 +47,7 @@ def insert_records(msserver_obj, data):
...
@@ -47,7 +47,7 @@ def insert_records(msserver_obj, data):
}
}
x
=
msserver_obj
.
insert_records
(
data
)
x
=
msserver_obj
.
insert_records
(
data
)
print
(
x
)
#
print(x)
return
x
return
x
...
...
scripts/cron_job.py
View file @
174ccfb1
...
@@ -17,7 +17,7 @@ MYSQL_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'msserver'
...
@@ -17,7 +17,7 @@ MYSQL_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'msserver'
class
configurations
(
Base
):
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.VARCHAR(10), nullable=False, primary_key=True)
id
=
sa
.
Column
(
sa
.
Integer
,
primary_key
=
True
)
id
=
sa
.
Column
(
sa
.
Integer
,
primary_key
=
True
)
job_run_date
=
sa
.
Column
(
sa
.
DATETIME
,
nullable
=
False
)
job_run_date
=
sa
.
Column
(
sa
.
DATETIME
,
nullable
=
False
)
...
@@ -65,24 +65,27 @@ class CRON:
...
@@ -65,24 +65,27 @@ class CRON:
def
insert_records
(
self
,
data
):
def
insert_records
(
self
,
data
):
res
=
self
.
session
.
query
(
configurations
)
.
count
()
res
=
self
.
session
.
query
(
configurations
)
.
count
()
print
(
res
)
# print(res)
logger
.
info
(
"total records in config {}"
.
format
(
res
))
if
res
==
0
:
if
res
==
0
:
self
.
session
.
add
(
self
.
insert
(
data
))
self
.
session
.
add
(
self
.
insert
(
data
))
self
.
session
.
commit
()
self
.
session
.
commit
()
else
:
else
:
data
=
self
.
getConfig
()
data
=
self
.
getConfig
()
from_zone
=
tz
.
gettz
(
'UTC'
)
# from_zone = tz.gettz('UTC')
to_zone
=
tz
.
gettz
(
'Asia/Kolkata'
)
# to_zone = tz.gettz('Asia/Kolkata')
print
(
to_zone
)
# print(to_zone)
utc
=
datetime
.
utcnow
()
# utc = datetime.utcnow()
utc
=
utc
.
replace
(
tzinfo
=
from_zone
)
# utc = utc.replace(tzinfo=from_zone)
# Convert time zone
# # Convert time zone
localtimenow
=
utc
.
astimezone
(
to_zone
)
# localtimenow = utc.astimezone(to_zone)
print
(
data
)
localtimenow
=
datetime
.
now
()
check
=
(
data
[
'job_run_date'
]
+
timedelta
(
minutes
=
data
[
'job_interval_minutes'
]))
.
astimezone
(
to_zone
)
# print(data)
print
(
check
,
localtimenow
)
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
:
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
data
[
'job_run_date'
]
=
localtimenow
self
.
session
.
add
(
self
.
insert
(
data
))
self
.
session
.
add
(
self
.
insert
(
data
))
self
.
session
.
commit
()
self
.
session
.
commit
()
...
@@ -91,11 +94,11 @@ class CRON:
...
@@ -91,11 +94,11 @@ class CRON:
def
insertConfigTime
(
self
,
job_date
):
def
insertConfigTime
(
self
,
job_date
):
data
=
{
data
=
{
"job_run_date"
:
job_date
,
"job_run_date"
:
job_date
,
"auto_update"
:
1
,
"auto_update"
:
MYSQL_CONFIG
[
'auto_update'
]
,
"shift_hours"
:
8
,
"shift_hours"
:
MYSQL_CONFIG
[
'shift_hours'
]
,
"group_event_period_seconds"
:
300
,
"group_event_period_seconds"
:
MYSQL_CONFIG
[
'group_event_period_seconds'
]
,
"over_time_hours"
:
3
,
"over_time_hours"
:
MYSQL_CONFIG
[
'over_time_hours'
]
,
"job_interval_minutes"
:
15
"job_interval_minutes"
:
MYSQL_CONFIG
[
'job_interval_minutes'
]
}
}
self
.
session
.
add
(
self
.
insert
(
data
))
self
.
session
.
add
(
self
.
insert
(
data
))
self
.
session
.
commit
()
self
.
session
.
commit
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment