Expire report files after 1 week, maximum for S3

We didn't see this in tests which use disk storage. But AWS S3 has a
maximum of one week for URL expiry.
This commit is contained in:
Maikel Linke
2023-05-05 14:23:41 +10:00
committed by Konrad
parent 5ae04a5a3e
commit 08aff56e20
2 changed files with 6 additions and 3 deletions

View File

@@ -2,6 +2,9 @@
# Stores a generated report.
class ReportBlob < ActiveStorage::Blob
# AWS S3 limits URL expiry to one week.
LIFETIME = 1.week
def self.create_for_upload_later!(filename)
# ActiveStorage discourages modifying a blob later but we need a blob
# before we know anything about the report file. It enables us to use the
@@ -12,7 +15,7 @@ class ReportBlob < ActiveStorage::Blob
checksum: "0",
content_type: content_type(filename),
).tap do |blob|
ActiveStorage::PurgeJob.set(wait: 1.month).perform_later(blob)
ActiveStorage::PurgeJob.set(wait: LIFETIME).perform_later(blob)
end
end
@@ -35,6 +38,6 @@ class ReportBlob < ActiveStorage::Blob
end
def expiring_service_url
url(expires_in: 1.month)
url(expires_in: LIFETIME)
end
end

View File

@@ -324,7 +324,7 @@ en:
subject: "Report ready"
heading: "Report ready for download"
intro: |
The link below will expire after one month.
The link below will expire after one week.
link_label: "%{name}"
shipment_mailer:
shipped_email: