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
328f479b
Commit
328f479b
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
make the response more useful for a ui
parent
b898e701
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/routes/jobs.py
+52
-2
52 additions, 2 deletions
inventory_provider/routes/jobs.py
with
52 additions
and
2 deletions
inventory_provider/routes/jobs.py
+
52
−
2
View file @
328f479b
import
json
import
logging
from
distutils.util
import
strtobool
...
...
@@ -75,5 +76,54 @@ def check_update_status():
@routes.route
(
"
log
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@common.require_accepts_json
def
load_task_log
():
tasks
=
monitor
.
load_task_log
(
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
])
return
jsonify
(
tasks
)
FINALIZATION_EVENTS
=
{
'
task-succeeded
'
,
'
task-failed
'
,
'
task-revoked
'
}
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
r
=
get_current_redis
(
config
)
cache_key
=
'
joblog:cached-response
'
result
=
r
.
get
(
cache_key
)
if
result
:
result
=
json
.
loads
(
result
.
decode
(
'
utf-8
'
))
else
:
result
=
{
'
pending
'
:
[],
'
warnings
'
:
[],
'
errors
'
:
[],
'
failed
'
:
[]
}
for
task
in
monitor
.
load_task_log
(
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]).
values
():
for
event
in
task
.
get
(
'
task-warning
'
,
[]):
result
[
'
warnings
'
].
append
(
event
[
'
message
'
])
for
event
in
task
.
get
(
'
task-error
'
,
[]):
result
[
'
errors
'
].
append
(
event
[
'
message
'
])
# build the description if task-received is available
description
=
None
if
'
task-received
'
in
task
:
event
=
task
[
'
task-received
'
][
0
]
description
=
f
'
{
event
[
"
name
"
]
}{
event
[
"
args
"
]
}
'
description
+=
f
'
:
{
event
[
"
uuid
"
]
}
'
if
'
task-failed
'
in
task
:
if
not
description
:
logger
.
error
(
'
found task-failed event without
'
f
'
task-received:
{
task
}
'
)
description
=
task
[
'
task-failed
'
][
0
][
'
uuid
'
]
result
[
'
failed
'
].
append
(
description
)
if
'
task-started
'
in
task
:
finished
=
set
(
task
.
keys
())
&
FINALIZATION_EVENTS
if
not
finished
:
if
not
description
:
logger
.
error
(
'
found task-started event without
'
f
'
task-received:
{
task
}
'
)
description
=
task
[
'
task-started
'
][
0
][
'
uuid
'
]
result
[
'
pending
'
].
append
(
description
)
if
not
result
[
'
pending
'
]:
r
.
set
(
cache_key
,
json
.
dumps
(
result
))
return
jsonify
(
result
)
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