Skip to content

Commit

Permalink
Retry deleting with onerror handler
Browse files Browse the repository at this point in the history
  • Loading branch information
qduanmu committed Dec 13, 2022
1 parent eda3c2d commit 23a8def
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 3 additions & 6 deletions openlcsd/flow/task_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import celery
import os
import shutil
from commoncode.fileutils import delete


class WorkflowWrapperTask(celery.Task):
Expand All @@ -14,17 +14,14 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
if comp_type != 'OCI' or args[0].get('parent'):
src_dest_dir = args[0].get('src_dest_dir')
if src_dest_dir and os.path.exists(src_dest_dir):
shutil.rmtree(src_dest_dir, ignore_errors=True)
delete(src_dest_dir)
# Only keep the source tarball for failed container components
if status == 'FAILURE' and 'src_dir' in args[0]:
pass
else:
tmp_src_filepath = args[0].get('tmp_src_filepath')
if tmp_src_filepath and os.path.exists(tmp_src_filepath):
if os.path.isdir(tmp_src_filepath):
shutil.rmtree(tmp_src_filepath, ignore_errors=True)
else:
os.remove(tmp_src_filepath)
delete(tmp_src_filepath)
super().after_return(
status, retval, task_id, args, kwargs, einfo)

Expand Down
3 changes: 2 additions & 1 deletion openlcsd/flow/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from requests.exceptions import HTTPError

from checksumdir import dirhash
from commoncode.fileutils import delete
from workflow.patterns.controlflow import IF
from workflow.patterns.controlflow import IF_ELSE
from packagedcode.rpm import parse as rpm_parse
Expand Down Expand Up @@ -512,7 +513,7 @@ def prepare_dest_dir(context, engine):
src_dir = tempfile.mkdtemp(
prefix='src_', dir=context.get('tmp_root_dir'))
if os.path.exists(src_dir):
shutil.rmtree(src_dir, ignore_errors=True)
delete(src_dir)
try:
os.makedirs(src_dir)
except OSError as err:
Expand Down

0 comments on commit 23a8def

Please sign in to comment.