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
26bf0a5b
Commit
26bf0a5b
authored
Jul 25, 2020
by
Akshay G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
local time
parent
301b249d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
65 deletions
+89
-65
Dockerfile
Dockerfile
+1
-1
cron-app.py
cron-app.py
+72
-60
requirements.txt
requirements.txt
+3
-1
scripts/cron_job.py
scripts/cron_job.py
+13
-3
No files found.
Dockerfile
View file @
26bf0a5b
...
...
@@ -24,4 +24,4 @@ ADD . /app
WORKDIR
/app
RUN
pip
install
-r
requirements.txt
RUN
rm
-rf
/var/lib/apt/lists/
*
&&
rm
-rf
/root/.cache/pip/
CMD
["python", "app.py"]
\ No newline at end of file
CMD
["python", "cron-app.py"]
cron-app.py
View file @
26bf0a5b
...
...
@@ -10,6 +10,8 @@ from scripts.common.config import MONGO_DB_OBJ, MONGO_SERVICE_COLL, HOST_CONFIG
from
datetime
import
datetime
,
timedelta
from
scripts.common.logsetup
import
logger
from
scripts.cron_job
import
*
from
datetime
import
datetime
from
dateutil
import
tz
get_in_out_dt_output
=
namedtuple
(
"output"
,
"dt_in_time dt_out_time punch_date"
)
...
...
@@ -25,8 +27,18 @@ 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
)
data
=
{
"job_run_date"
:
datetime
.
now
(),
"job_run_date"
:
central
,
"auto_update"
:
1
,
"shift_hours"
:
8
,
"group_event_period_seconds"
:
300
,
...
...
requirements.txt
View file @
26bf0a5b
...
...
@@ -3,3 +3,5 @@ flask
flask_cors
sqlalchemy
mysqlclient
pymssql
python-dateutil
scripts/cron_job.py
View file @
26bf0a5b
...
...
@@ -10,7 +10,7 @@ from sqlalchemy.ext.declarative import declarative_base
from
scripts.common.logsetup
import
logger
from
scripts.common.config
import
MONGO_DB_OBJ
,
MONGO_SERVICE_COLL
from
datetime
import
timedelta
from
dateutil
import
tz
Base
=
declarative_base
()
MYSQL_CONFIG
=
MONGO_DB_OBJ
[
MONGO_SERVICE_COLL
]
.
find_one
({
'configId'
:
'msserver'
})
.
get
(
'config'
)
...
...
@@ -63,6 +63,7 @@ class CRON:
return
self
.
config
def
insert_records
(
self
,
data
):
res
=
self
.
session
.
query
(
configurations
)
.
count
()
print
(
res
)
if
res
==
0
:
...
...
@@ -70,10 +71,19 @@ class CRON:
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
)
if
data
[
'auto_update'
]
==
1
and
(
data
[
'job_run_date'
]
+
timedelta
(
minutes
=
data
[
'job_interval_minutes'
]))
<
datetime
.
now
():
check
=
(
data
[
'job_run_date'
]
+
timedelta
(
minutes
=
data
[
'job_interval_minutes'
]))
.
astimezone
(
to_zone
)
print
(
check
,
localtimenow
)
if
data
[
'auto_update'
]
==
1
and
check
<
localtimenow
:
print
(
data
[
'job_run_date'
],
data
[
'job_interval_minutes'
])
data
[
'job_run_date'
]
=
datetime
.
now
()
data
[
'job_run_date'
]
=
localtimenow
self
.
session
.
add
(
self
.
insert
(
data
))
self
.
session
.
commit
()
return
True
...
...
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