Skip to content

Commit

Permalink
de-duplicate error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimpe committed Oct 10, 2024
1 parent ae86249 commit 6f45359
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tdrs-backend/tdpservice/scheduling/parser_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
logger = logging.getLogger(__name__)


def set_reparse_file_meta_model_failed_state(file_meta):
"""Set ReparseFileMeta fields to indicate a parse failure."""
file_meta.finished = True
file_meta.success = False
file_meta.finished_at = timezone.now()
file_meta.save()


@shared_task
def parse(data_file_id, reparse_id=None):
"""Send data file for processing."""
Expand Down Expand Up @@ -71,10 +79,7 @@ def parse(data_file_id, reparse_id=None):
"error"
)
if reparse_id:
file_meta.finished = True
file_meta.success = False
file_meta.finished_at = timezone.now()
file_meta.save()
set_reparse_file_meta_model_failed_state(file_meta)
except Exception as e:
generate_error = make_generate_parser_error(data_file, None)
error = generate_error(schema=None,
Expand All @@ -93,7 +98,4 @@ def parse(data_file_id, reparse_id=None):
f"see if manual intervention is required. Exception: \n{e}"),
"critical")
if reparse_id:
file_meta.finished = True
file_meta.success = False
file_meta.finished_at = timezone.now()
file_meta.save()
set_reparse_file_meta_model_failed_state(file_meta)

0 comments on commit 6f45359

Please sign in to comment.