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
56cf8b65
Commit
56cf8b65
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
standalone task event monitor app
parent
cb3dab60
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
+69
-0
69 additions, 0 deletions
inventory_provider/tasks/monitor.py
with
69 additions
and
0 deletions
inventory_provider/tasks/monitor.py
0 → 100644
+
69
−
0
View file @
56cf8b65
import
json
import
logging
from
inventory_provider.tasks.worker
import
app
from
inventory_provider.tasks.common
import
get_current_redis
from
threading
import
Thread
logger
=
logging
.
getLogger
(
__name__
)
INFO_EVENT_TYPES
=
(
'
task-info
'
,
'
task-warning
'
,
'
task-error
'
)
def
_monitor_proc
(
config
):
state
=
app
.
events
.
State
()
def
_log_event
(
event
):
state
.
event
(
event
)
if
not
event
[
'
type
'
].
startswith
(
'
task-
'
):
return
key
=
f
'
joblog:
{
event
[
"
uuid
"
]
}
:
{
event
[
"
type
"
]
}
'
if
event
[
'
type
'
]
in
INFO_EVENT_TYPES
:
key
+=
f
'
:
{
event
[
"
clock
"
]
}
'
r
=
get_current_redis
(
config
)
r
.
set
(
key
,
json
.
dumps
(
event
))
logger
.
debug
(
f
'
{
key
}
:
{
json
.
dumps
(
event
)
}
'
)
with
app
.
connection
()
as
connection
:
recv
=
app
.
events
.
Receiver
(
connection
,
handlers
=
{
'
*
'
:
_log_event
,
})
recv
.
capture
(
limit
=
None
,
timeout
=
None
,
wakeup
=
True
)
def
start_monitoring
():
thread
=
Thread
(
target
=
_monitor_proc
,
args
=
())
thread
.
start
()
def
clear_joblog
(
r
):
"""
:param r:
:return:
"""
rp
=
r
.
pipeline
()
for
key
in
r
.
scan_iter
(
'
joblog:*
'
):
rp
.
delete
(
key
)
rp
.
execute
()
if
__name__
==
'
__main__
'
:
import
os
from
inventory_provider
import
config
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
filename
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
..
'
,
'
config-sentinel.json
'
)
with
open
(
filename
)
as
f
:
params
=
config
.
load
(
f
)
_monitor_proc
(
params
)
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