Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Workers
Base Worker
Commits
528bc322
Commit
528bc322
authored
3 years ago
by
Valentin Rigal
Browse files
Options
Downloads
Patches
Plain Diff
Use the generic error catch and handle exceptions when patching to the Error state
parent
25d4fff2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex_worker/worker/__init__.py
+17
-26
17 additions, 26 deletions
arkindex_worker/worker/__init__.py
with
17 additions
and
26 deletions
arkindex_worker/worker/__init__.py
+
17
−
26
View file @
528bc322
...
...
@@ -27,11 +27,6 @@ class ActivityState(Enum):
Error
=
"
error
"
class
ConflictResponse
(
ErrorResponse
):
# Custom Exception type for HTTP 409 conflict
pass
class
ElementsWorker
(
BaseWorker
,
ClassificationMixin
,
...
...
@@ -134,24 +129,23 @@ class ElementsWorker(
# Process the element and report its progress if activities are enabled
try
:
self
.
update_activity
(
element
.
id
,
ActivityState
.
Started
)
except
ConflictResponse
as
e
:
# Skip this element in case of conflict while initializing the activity
except
ErrorResponse
as
e
:
if
e
.
status_code
!=
409
:
raise
e
# 409 conflict error when updating the state of an activity to "started" mean that we
# cannot process this element. We assume that the reason is that the state transition
# was forbidden i.e. that the activity was already in a started or processed state.
# This allow concurrent access to an element activity between multiple processes.
# Element should not be counted as failed as it is probably handled somewhere else.
logger
.
warning
(
f
"
Cannot start processing element
{
element
.
id
}
due to a conflict
,
"
f
"
a
nother process could have processed it with the same version already
:
{
e
.
content
}
"
f
"
Cannot start processing element
{
element
.
id
}
due to a conflict
.
"
f
"
A
nother process could have processed it with the same version already
.
"
)
continue
self
.
process_element
(
element
)
try
:
self
.
update_activity
(
element
.
id
,
ActivityState
.
Processed
)
except
ConflictResponse
as
e
:
# Do not count this element as failed
logger
.
warning
(
f
"
Element
{
element
.
id
}
was processed but its activity could not be updated:
{
e
.
content
}
"
)
continue
self
.
update_activity
(
element
.
id
,
ActivityState
.
Processed
)
except
Exception
as
e
:
# Handle errors occurring while retrieving, processing or patching the activity
o
f th
e
element
# Handle errors occurring while retrieving, processing or patching the activity f
or
th
is
element
.
# Count the element as failed in case the activity update to "started" failed with no conflict.
# This prevent from processing the element
failed
+=
1
...
...
@@ -169,7 +163,11 @@ class ElementsWorker(
exc_info
=
e
if
self
.
args
.
verbose
else
None
,
)
if
element
:
self
.
update_activity
(
element
.
id
,
ActivityState
.
Error
)
# Try to update the activity to error state regardless of the response
try
:
self
.
update_activity
(
element
.
id
,
ActivityState
.
Error
)
except
Exception
:
pass
self
.
report
.
error
(
element_id
,
e
)
# Save report as local artifact
...
...
@@ -221,13 +219,6 @@ class ElementsWorker(
logger
.
warning
(
f
"
Failed to update activity of element
{
element_id
}
to
{
state
.
value
}
due to an API error:
{
e
.
content
}
"
)
# 409 conflict error when updating the state of an activity mean that we cannot
# process this element. We assume that the reason is that the state transition
# was forbidden i.e. that the activity was already in a started or processed state.
# This allow concurrent access to an element activity between multiple processes.
# Element should not be counted as failed as it is probably handled somewhere else.
if
e
.
status_code
==
409
:
raise
ConflictResponse
(
e
)
raise
e
logger
.
debug
(
f
"
Updated activity of element
{
element_id
}
to
{
state
}
"
)
...
...
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