diff --git a/arkindex_worker/worker/__init__.py b/arkindex_worker/worker/__init__.py index a2c47990e7643c57fb3887a1956c171993366e60..fccde23bb123dd11c42198e51c705b784e493813 100644 --- a/arkindex_worker/worker/__init__.py +++ b/arkindex_worker/worker/__init__.py @@ -126,17 +126,25 @@ class ElementsWorker( # Process the element and report its progress if activities are enabled response = self.update_activity(element.id, ActivityState.Started) - if isinstance(response, ErrorResponse) and response.status_code == 400: - # Bad request error when setting an activity to "started" mean that we cannot + if isinstance(response, ErrorResponse) and response.status_code == 409: + # 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 # was forbidden i.e. that the activity was already in a started or processed state. # This allow concurrent access to an element activity. - # Element is not counted as failed as it is handled by another process. - logger.info( - f'Cannot start processing element "{element.id}". ' + # Element is not counted as failed as it is probably handled by another process. + logger.warning( + f"Cannot start processing element {element.id} due to a conflict. " "Another process could have processed it with the same version already." ) 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.update_activity(element.id, ActivityState.Processed) except Exception as e: @@ -215,3 +223,4 @@ class ElementsWorker( logger.warning( f"Failed to update activity of element {element_id} to {state.value}: {e}" ) + return e