Skip to content

Commit

Permalink
Fixes for task Cancellation Handling (#1004)
Browse files Browse the repository at this point in the history
* Only call cancel_subtasks for V2 and dont overwrite CANCELLED status on error handle

* Skip traceback storage if not given

* Ignore errors on temp dir clean-up
  • Loading branch information
sambles committed Mar 26, 2024
1 parent 6f6d3ac commit 7e02130
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/model_execution_worker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __enter__(self):

def __exit__(self, exc_type, exc_value, traceback):
if not self.persist and os.path.isdir(self.name):
shutil.rmtree(self.name)
shutil.rmtree(self.name, ignore_errors=True)


def get_oasislmf_config_path(settings, model_id=None):
Expand Down
44 changes: 24 additions & 20 deletions src/server/oasisapi/analyses/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,19 @@ def record_run_analysis_failure(analysis_pk, initiator_pk, traceback):
analysis = Analysis.objects.get(pk=analysis_pk)
analysis.status = Analysis.status_choices.RUN_ERROR
analysis.task_finished = timezone.now()
analysis.save()

random_filename = '{}.txt'.format(uuid.uuid4().hex)
with TemporaryFile() as tmp_file:
tmp_file.write(traceback.encode('utf-8'))
analysis.run_traceback_file = RelatedFile.objects.create(
file=File(tmp_file, name=random_filename),
filename=f'analysis_{analysis_pk}_run_traceback.txt',
content_type='text/plain',
creator=get_user_model().objects.get(pk=initiator_pk),
)
if traceback:
random_filename = '{}.txt'.format(uuid.uuid4().hex)
with TemporaryFile() as tmp_file:
tmp_file.write(traceback.encode('utf-8'))
analysis.run_traceback_file = RelatedFile.objects.create(
file=File(tmp_file, name=random_filename),
filename=f'analysis_{analysis_pk}_run_traceback.txt',
content_type='text/plain',
creator=get_user_model().objects.get(pk=initiator_pk),
)
else:
logging.error('Could not extract traceback')

# remove the current command log file
if analysis.run_log_file:
Expand All @@ -480,17 +482,19 @@ def record_generate_input_failure(analysis_pk, initiator_pk, traceback):
analysis = Analysis.objects.get(pk=analysis_pk)
analysis.status = Analysis.status_choices.INPUTS_GENERATION_ERROR
analysis.task_finished = timezone.now()
analysis.save()

random_filename = '{}.txt'.format(uuid.uuid4().hex)
with TemporaryFile() as tmp_file:
tmp_file.write(traceback.encode('utf-8'))
analysis.input_generation_traceback_file = RelatedFile.objects.create(
file=File(tmp_file, name=random_filename),
filename=f'analysis_{analysis_pk}_generation_traceback.txt',
content_type='text/plain',
creator=get_user_model().objects.get(pk=initiator_pk),
)
if traceback:
random_filename = '{}.txt'.format(uuid.uuid4().hex)
with TemporaryFile() as tmp_file:
tmp_file.write(traceback.encode('utf-8'))
analysis.input_generation_traceback_file = RelatedFile.objects.create(
file=File(tmp_file, name=random_filename),
filename=f'analysis_{analysis_pk}_generation_traceback.txt',
content_type='text/plain',
creator=get_user_model().objects.get(pk=initiator_pk),
)
else:
logging.error('Could not extract traceback')

analysis.save()
except Exception as e:
Expand Down

0 comments on commit 7e02130

Please sign in to comment.