Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete expired files with management command #518

Merged
merged 3 commits into from
Jun 5, 2024

Conversation

rachaelcodes
Copy link
Contributor

Context

Now that we have a way to track when files were last used, we can remove them with a management command. There is still some discussion about how this command will be triggered, and this might change over time.

There is a future change to come that will also remove expired Chats and ChatHistory.

Changes proposed in this pull request

Creates a management command that checks for files past their expiry date and removes their chunks from elastic storage, deleted the file contents from S3 and then transitions them to 'deleted' in Django (so we keep a record).

If there is an error in the elastic or S3 deletion, the file is marked as 'errored' in Django (a new status type). Errors are logged. We need to develop a process of reviewing and handling batches of errors.

Other changes

  • Django views calling the core-api now check for all potential issues with connection, not just HTTP response ones (e.g. connection issues). We could consider handling S3 errors in future cases
  • 'errored' files are hidden from users as well as 'deleted' ones
  • whitespace fixes picked up by the linter in django_app/tests_playwright/pages.py

Guidance to review

Do you agree with the approach? Is there any other error handling needed? What else can we do around files that are partially deleted?

Relevant links

https://technologyprogramme.atlassian.net/browse/REDBOX-234

Things to check

  • I have added any new ENV vars in all deployed environments
  • I have tested any code added or changed
  • I have run integration tests

@rachaelcodes rachaelcodes marked this pull request as ready for review June 5, 2024 08:54
Copy link
Contributor

@brunns brunns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.



@pytest.mark.parametrize(
("mock_datetime", "should_delete"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nitpick - I wouldn't call this a mock really.


try:
core_api.delete_file(file.core_file_uuid, file.user)
file.delete_from_s3()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be part of the File.delete method 🤔 , probably doesnt add much and just over-complicates things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently have a File.delete that actually deletes the file, whereas this just removes the file contents but keeps a record of the File in Django (for auditing processes). I think this was a product decision a few weeks ago.

Copy link
Collaborator

@gecBurton gecBurton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super clear, as always!

@rachaelcodes rachaelcodes merged commit e7146e1 into main Jun 5, 2024
9 checks passed
@rachaelcodes rachaelcodes deleted the feature/REDBOX-234-deletion-management-command branch June 5, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants