Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
geant-swd
dashboardv3
inventory-provider
Commits
b665f0fa
Commit
b665f0fa
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
allow clean shutdown of monitoring process (testing only)
parent
c93ab2db
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/tasks/monitor.py
+17
-6
17 additions, 6 deletions
inventory_provider/tasks/monitor.py
with
17 additions
and
6 deletions
inventory_provider/tasks/monitor.py
+
17
−
6
View file @
b665f0fa
...
...
@@ -25,7 +25,7 @@ INFO_EVENT_TYPES = ('task-info', 'task-warning', 'task-error')
def
_save_proc
(
db_queue
,
params
,
dbid
):
"""
save redis events to a specific db
:param q:
:param q:
queue for receiving events, None means to stop
:param params:
:param dbid:
:return:
...
...
@@ -33,11 +33,16 @@ def _save_proc(db_queue, params, dbid):
def
_save_events
(
r
,
q
):
while
True
:
event
=
q
.
get
()
if
not
event
:
return
r
.
set
(
event
[
'
key
'
],
event
[
'
value
'
])
while
True
:
try
:
_save_events
(
_get_redis
(
config
=
params
,
dbid
=
dbid
),
db_queue
)
# we only reach here if the event loop terminated
# normally, because None was sent
return
except
RedisError
:
logger
.
exception
(
'
redis i/o exception, reconnecting
'
)
# TODO: do something to terminate the process ...?
...
...
@@ -57,15 +62,14 @@ def run():
state
=
app
.
events
.
State
()
db_queue
s
=
[]
thread
s
=
[]
for
dbid
in
config_params
[
'
redis-databases
'
]:
q
=
queue
.
Queue
()
t
=
threading
.
Thread
(
target
=
_save_proc
,
args
=
[
q
,
config_params
,
dbid
])
t
.
start
()
db_queues
.
append
(
q
)
# TODO: graceful shutdown? save threads and join later?
threads
.
append
({
'
thread
'
:
t
,
'
queue
'
:
q
})
def
_log_event
(
event
):
state
.
event
(
event
)
...
...
@@ -78,8 +82,8 @@ def run():
key
+=
f
'
:
{
event
[
"
clock
"
]
}
'
value
=
json
.
dumps
(
event
)
for
q
in
db_queue
s
:
q
.
put
({
'
key
'
:
key
,
'
value
'
:
value
})
for
t
in
thread
s
:
t
[
'
queue
'
]
.
put
({
'
key
'
:
key
,
'
value
'
:
value
})
logger
.
debug
(
f
'
{
key
}
:
{
json
.
dumps
(
event
)
}
'
)
...
...
@@ -89,6 +93,13 @@ def run():
})
recv
.
capture
(
limit
=
None
,
timeout
=
None
,
wakeup
=
True
)
logger
.
warning
(
'
normally we should never reach here
'
)
# allow child threads to terminate
for
t
in
threads
:
t
[
'
queue
'
].
put
(
None
)
t
[
'
thread
'
].
join
()
def
clear_joblog
(
r
):
"""
...
...
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