Add celery beat task, archive_pending_files to automatically archives files that have been created but not made live after 24 hours.#4875
Open
rparke wants to merge 10 commits into
Conversation
b4a0df2 to
8ed0f9d
Compare
rparke
commented
Jun 8, 2026
rparke
commented
Jun 8, 2026
rparke
commented
Jun 8, 2026
…e files that have been created but not made live after 24 hours. This is vital cleanup work that ensures that these stale files don't persist and are properly cleaned up, eventually being removed from S3 too.
8ed0f9d to
1775df8
Compare
rparke
commented
Jun 9, 2026
CrystalPea
reviewed
Jun 9, 2026
CrystalPea
left a comment
Contributor
There was a problem hiding this comment.
Nice work! I left a few comments 🙌🏼
| datetime.datetime.utcnow() - TemplateEmailFile.created_at | ||
| > datetime.timedelta(hours=current_app.config.get("TEMPLATE_EMAIL_FILE_ARCHIVE_PERIOD_IN_HOURS")), | ||
| ).all() | ||
| for file in files_in_pending: |
Contributor
There was a problem hiding this comment.
Could we archive all pending files in a single transaction, instead of looping? That will make the query much much faster.
Contributor
Author
There was a problem hiding this comment.
I don't know how much faster this will make the query because we don't get thousands of new files a day (at the moment) can update if needed.
this wraps everything up in a single transaction and stops the template version drifting (edge case) in the archive loop
joybytes
reviewed
Jun 12, 2026
joybytes
reviewed
Jun 12, 2026
joybytes
reviewed
Jun 12, 2026
joybytes
reviewed
Jun 12, 2026
joybytes
reviewed
Jun 12, 2026
Co-authored-by: joybytes <171517790+joybytes@users.noreply.github.com>
…alphagov/notifications-api into rp-cleanup-pending-files-scheduled-task
joybytes
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is vital cleanup work that ensures that these stale files don't persist and are properly cleaned up, eventually being removed from S3 too when they are picked up by the scheduled task:
remove-archived-template-email-files-from-s3.24 hours has been selected because that's the session timeout for our users and should be long enough that if they were going to make the file live, they'd have done it.