Skip to content

Commit

Permalink
simplify data clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiPetukhov committed Sep 13, 2024
1 parent f60e6e4 commit d8763a8
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions agent/worker/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,7 @@ def task_clear_tasks_dir(self):
"Start background task: Clearing Tasks data [_to_remove directory detected]"
)
try:
for subdir_n in os.listdir(tmp_dir):
dir_task = os.path.join(tmp_dir, subdir_n)
TaskDirCleaner(dir_task).clean_forced()
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear tasks data", exc_info=True)
else:
Expand All @@ -710,9 +708,7 @@ def task_clear_tasks_dir(self):
task_dir = constants.AGENT_TASKS_DIR()
shutil.move(task_dir, tmp_dir)
os.makedirs(task_dir)
for subdir_n in os.listdir(tmp_dir):
dir_task = os.path.join(tmp_dir, subdir_n)
TaskDirCleaner(dir_task).clean_forced()
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear tasks data", exc_info=True)
else:
Expand All @@ -727,8 +723,7 @@ def task_clear_pip_cache(self):
"Start background task: Clearing pip cache [_to_remove directory detected]"
)
try:
cleaner = AppDirCleaner(self.logger)
cleaner.clean_pip_cache(pip_cache_dir=tmp_dir)
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear pip cache", exc_info=True)
else:
Expand All @@ -740,8 +735,7 @@ def task_clear_pip_cache(self):
try:
shutil.move(constants.APPS_PIP_CACHE_DIR(), tmp_dir)
os.makedirs(constants.APPS_PIP_CACHE_DIR())
cleaner = AppDirCleaner(self.logger)
cleaner.clean_pip_cache(pip_cache_dir=tmp_dir)
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear pip cache", exc_info=True)
else:
Expand All @@ -756,8 +750,7 @@ def task_clear_apps_data(self):
"Start background task: Clearing apps data [_to_remove directory detected]"
)
try:
cleaner = AppDirCleaner(self.logger)
cleaner.clean_apps_cache(apps_cache_dir=tmp_dir)
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear apps data", exc_info=True)
else:
Expand All @@ -769,8 +762,7 @@ def task_clear_apps_data(self):
try:
shutil.move(constants.AGENT_APPS_CACHE_DIR(), tmp_dir)
os.makedirs(constants.AGENT_APPS_CACHE_DIR())
cleaner = AppDirCleaner(self.logger)
cleaner.clean_apps_cache(apps_cache_dir=tmp_dir)
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear apps data", exc_info=True)
else:
Expand Down

0 comments on commit d8763a8

Please sign in to comment.