cleanup the queue flag during cleanup job
This commit is contained in:
parent
da590cc73a
commit
cb5f922bb6
1 changed files with 18 additions and 2 deletions
|
@ -2,9 +2,25 @@ class CleanupStaleExportsJob < ApplicationJob
|
||||||
queue_as :cron
|
queue_as :cron
|
||||||
|
|
||||||
def perform(*args)
|
def perform(*args)
|
||||||
ActiveStorage::Attachment.where(
|
attachments = ActiveStorage::Attachment.where(
|
||||||
"name in ('csv_export_file', 'ods_export_file', 'xlsx_export_file') and created_at < ?",
|
"name in ('csv_export_file', 'ods_export_file', 'xlsx_export_file') and created_at < ?",
|
||||||
Procedure::MAX_DUREE_CONSERVATION_EXPORT.ago
|
Procedure::MAX_DUREE_CONSERVATION_EXPORT.ago
|
||||||
).find_each(&:purge_later)
|
)
|
||||||
|
attachments.each do |attachment|
|
||||||
|
procedure = Procedure.find(attachment.record_id)
|
||||||
|
# export can't be queued if it's already attached
|
||||||
|
# so we clean the flag up just in case it was not removed during
|
||||||
|
# the asynchronous generation
|
||||||
|
case attachment.name
|
||||||
|
when 'csv_export_file'
|
||||||
|
procedure.update(csv_export_queued: false)
|
||||||
|
when 'ods_export_file'
|
||||||
|
procedure.update(ods_export_queued: false)
|
||||||
|
when 'xlsx_export_file'
|
||||||
|
procedure.update(xlsx_export_queued: false)
|
||||||
|
end
|
||||||
|
# and we remove the stale attachment
|
||||||
|
attachment.purge_later
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue