Skip to content

Commit

Permalink
fix: Fix delete_step to only run finish() if error isn't unexpected
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jan 5, 2024
1 parent e8d2c4e commit 1beb4da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion process/management/commands/file_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def callback(client_state, channel, method, properties, input_message):
try:
with delete_step(
ProcessingStep.Name.LOAD,
collection_file_id=collection_file_id,
finish=finish,
finish_args=(collection_id, collection_file_id),
collection_file_id=collection_file_id,
):
with transaction.atomic():
collection_file = CollectionFile.objects.select_related("collection").get(pk=collection_file_id)
Expand Down
14 changes: 7 additions & 7 deletions process/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,26 @@ def create_step(name, collection_id, **kwargs):


@contextmanager
def delete_step(*args, finish=None, finish_args=(), **kwargs):
def delete_step(*args, **kwargs):
try:
yield
# See the errback() function in the decorator() function. If a duplicate message is received, delete the step, so
# that the collection is completable. Don't delete the step if the error was unexpected.
except (AlreadyExists, InvalidFormError, IntegrityError):
_delete_step(*args, **kwargs)
_delete_step_and_finish(*args, **kwargs)
raise
else:
_delete_step(*args, **kwargs)
finally:
if finish:
finish(*finish_args)
_delete_step_and_finish(*args, **kwargs)


def _delete_step(step_type, **kwargs):
def _delete_step_and_finish(step_type, finish=None, finish_args=(), **kwargs):
# kwargs can include collection_id, collection_file_id and ocid.
processing_steps = ProcessingStep.objects.filter(name=step_type, **kwargs)

if processing_steps.exists():
processing_steps.delete()
else:
logger.warning("No such processing step found: %s: %s", step_type, kwargs)

if finish:
finish(*finish_args)

0 comments on commit 1beb4da

Please sign in to comment.