-
Notifications
You must be signed in to change notification settings - Fork 33
Add celery beat task, archive_pending_files to automatically archives files that have been created but not made live after 24 hours.
#4875
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,9 +137,22 @@ def dao_make_pending_template_email_file_live(template_email_file: TemplateEmail | |
| @version_class( | ||
| VersionOptions(TemplateEmailFile, history_class=TemplateEmailFileHistory), | ||
| ) | ||
| def dao_archive_template_email_file(file_to_archive, archived_by_id, template_version): | ||
| def dao_archive_template_email_file(file_to_archive, archived_by_id, template_version=None): | ||
| if not template_version: | ||
| template_version = Template.query.get(file_to_archive.template_id).version | ||
| if not file_to_archive.archived_at: | ||
| file_to_archive.archived_at = datetime.datetime.utcnow() | ||
| file_to_archive.archived_by_id = archived_by_id | ||
| file_to_archive.template_version = template_version | ||
| db.session.add(file_to_archive) | ||
|
|
||
|
|
||
| def dao_archive_pending_files(): | ||
| files_in_pending = TemplateEmailFile.query.filter( | ||
| TemplateEmailFile.pending, | ||
| datetime.datetime.utcnow() - TemplateEmailFile.created_at | ||
|
joybytes marked this conversation as resolved.
|
||
| > 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| dao_archive_template_email_file(file, archived_by_id=file.created_by_id) | ||
| return len(files_in_pending) | ||
|
joybytes marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.