Skip to content

Commit

Permalink
Merge pull request #77 from yankovs/Fix/safe-job-deletion
Browse files Browse the repository at this point in the history
Fix: make job deletion safer
  • Loading branch information
danielplohmann committed Jun 20, 2024
2 parents db4bac6 + 0a4e99d commit 2bbe7f5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mcrit/libs/mongoqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,18 @@ def delete_job(self, job_id, with_result=True):
print(deletable_job)
if "file_params" in deletable_job["payload"]:
file_params_dict = json.loads(deletable_job["payload"]["file_params"])
for k, file_object_id in file_params_dict.items():
self._getFs().delete(ObjectId(file_object_id))
for _, file_object_id in file_params_dict.items():
file_object_id = ObjectId(file_object_id)
# update gridFs entry of file to not link
# to this job anymore
self._getFs().update_one(
{"_id": file_object_id}, {"$pull": {"metadata.jobs": str(job_id)}}
)
# check if file is safe to delete
if self._getFs().count_documents(
{"_id": file_object_id, "metadata.jobs": [], "metadata.tmp_lock": 0}
) > 0:
self._getFs().delete(file_object_id)
if with_result:
# delete result from GridFS
self._getFs().delete(ObjectId(deletable_job["result"]))
Expand Down

0 comments on commit 2bbe7f5

Please sign in to comment.