Skip to content
Snippets Groups Projects
Commit ef3a9565 authored by Valentin Rigal's avatar Valentin Rigal Committed by Bastien Abadie
Browse files

Handle backend 409 conflict error code

parent d1992513
No related branches found
No related tags found
No related merge requests found
...@@ -128,17 +128,25 @@ class ElementsWorker( ...@@ -128,17 +128,25 @@ class ElementsWorker(
# Process the element and report its progress if activities are enabled # Process the element and report its progress if activities are enabled
response = self.update_activity(element.id, ActivityState.Started) response = self.update_activity(element.id, ActivityState.Started)
if isinstance(response, ErrorResponse) and response.status_code == 400: if isinstance(response, ErrorResponse) and response.status_code == 409:
# Bad request error when setting an activity to "started" mean that we cannot # 409 conflict error when setting an activity to "started" mean that we cannot
# process this element. We assume that the reason is that the state transition # 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. # was forbidden i.e. that the activity was already in a started or processed state.
# This allow concurrent access to an element activity. # This allow concurrent access to an element activity.
# Element is not counted as failed as it is handled by another process. # Element is not counted as failed as it is probably handled by another process.
logger.info( logger.warning(
f'Cannot start processing element "{element.id}". ' f"Cannot start processing element {element.id} due to a conflict. "
"Another process could have processed it with the same version already." "Another process could have processed it with the same version already."
) )
continue continue
elif isinstance(response, Exception):
# Count the element as failed in case the activity update to "started" failed with no conflict.
# This prevent from processing the element
logger.warning(
f"Element {element.id} is counted as failed because its activity could not be initialized."
)
failed += 1
continue
self.process_element(element) self.process_element(element)
self.update_activity(element.id, ActivityState.Processed) self.update_activity(element.id, ActivityState.Processed)
except Exception as e: except Exception as e:
...@@ -217,3 +225,4 @@ class ElementsWorker( ...@@ -217,3 +225,4 @@ class ElementsWorker(
logger.warning( logger.warning(
f"Failed to update activity of element {element_id} to {state.value}: {e}" f"Failed to update activity of element {element_id} to {state.value}: {e}"
) )
return e
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment