Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
07d40437
Commit
07d40437
authored
2 years ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Clean shutdown on SIGTERM
parent
58055030
No related branches found
No related tags found
1 merge request
!683
[Webservice] Restructure database to give more meaningful success/failure information
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
webservice/job_monitor.py
+20
-1
20 additions, 1 deletion
webservice/job_monitor.py
with
20 additions
and
1 deletion
webservice/job_monitor.py
+
20
−
1
View file @
07d40437
...
...
@@ -3,6 +3,7 @@ import argparse
import
json
import
locale
import
logging
import
signal
import
time
from
datetime
import
datetime
,
timezone
from
pathlib
import
Path
...
...
@@ -93,6 +94,13 @@ class JobsMonitor:
self
.
kafka_topic
=
config
[
'
kafka
'
][
'
topic
'
]
self
.
time_interval
=
int
(
config
[
'
web-service
'
][
'
job-update-interval
'
])
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
self
.
job_db
.
close
()
self
.
kafka_prod
.
close
(
timeout
=
5
)
def
run
(
self
):
while
True
:
try
:
...
...
@@ -293,6 +301,9 @@ class JobsMonitor:
log
.
error
(
"
Failed to update MDC dark run id %s
"
,
dark_run_id
)
log
.
error
(
Errors
.
MDC_RESPONSE
.
format
(
response
))
def
interrupted
(
signum
,
frame
):
raise
KeyboardInterrupt
def
main
(
argv
=
None
):
# Ensure files are opened as UTF-8 by default, regardless of environment.
locale
.
setlocale
(
locale
.
LC_CTYPE
,
(
'
en_US
'
,
'
UTF-8
'
))
...
...
@@ -318,7 +329,15 @@ def main(argv=None):
)
# DEBUG logs from kafka-python are very verbose, so we'll turn them off
logging
.
getLogger
(
'
kafka
'
).
setLevel
(
logging
.
INFO
)
JobsMonitor
(
config
).
run
()
# Treat SIGTERM like SIGINT (Ctrl-C) & do a clean shutdown
signal
.
signal
(
signal
.
SIGTERM
,
interrupted
)
with
JobsMonitor
(
config
)
as
jm
:
try
:
jm
.
run
()
except
KeyboardInterrupt
:
logging
.
info
(
"
Shutting down on SIGINT/SIGTERM
"
)
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment