Skip to content

Commit

Permalink
fix: remove all data from db when datasource expire
Browse files Browse the repository at this point in the history
  • Loading branch information
VDigitall committed May 10, 2021
1 parent 5f9a545 commit b6feba9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ def cleanup_upload(object_id, model=None, lang_code="en"):
"Skip datasource cleanup %s, expired_at in future %s"
% (datasource.id, datasource.expired_at.isoformat())
)
cleanup_upload.delay(object_id, model=model, lang_code=lang_code)
return
datasource_path = os.path.dirname(datasource.file.path)
shutil.rmtree(datasource_path, ignore_errors=True)
datasource.deleted = True
datasource.save(update_fields=["deleted"])
logger.debug("Remove all data from %s%s" % (settings.MEDIA_ROOT, datasource.id))
datasource.delete()
logger.debug("Remove all data from %s" % (datasource_path))


@celery_app.task
Expand Down
4 changes: 2 additions & 2 deletions core/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def test_success(self, upload_obj):
assert not upload_obj.deleted

cleanup_upload(upload_obj.id, model=self.model)
upload_obj = Upload.objects.get(id=upload_obj.id)
assert upload_obj.deleted
with pytest.raises(Upload.DoesNotExist):
Upload.objects.get(id=upload_obj.id)

def test_skip_cleanup(self, upload_obj):
expired_at = timezone.now() + timedelta(minutes=1)
Expand Down

0 comments on commit b6feba9

Please sign in to comment.