From 4a9ef5d12ec9817d362df941ce8044a5741486d6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 21 May 2019 11:36:19 +0200 Subject: [PATCH 1/2] Always use purge_later --- app/controllers/gestionnaires/dossiers_controller.rb | 2 +- app/controllers/users/dossiers_controller.rb | 2 +- app/models/champs/piece_justificative_champ.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/gestionnaires/dossiers_controller.rb b/app/controllers/gestionnaires/dossiers_controller.rb index d7f7d06fa..02512b173 100644 --- a/app/controllers/gestionnaires/dossiers_controller.rb +++ b/app/controllers/gestionnaires/dossiers_controller.rb @@ -143,7 +143,7 @@ module Gestionnaires def purge_champ_piece_justificative @champ = dossier.champs_private.find(params[:champ_id]) - @champ.piece_justificative_file.purge + @champ.piece_justificative_file.purge_later flash.notice = 'La pièce jointe a bien été supprimée.' end diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 9f3bce5e9..420a81891 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -239,7 +239,7 @@ module Users def purge_champ_piece_justificative @champ = dossier.champs.find(params[:champ_id]) - @champ.piece_justificative_file.purge + @champ.piece_justificative_file.purge_later flash.notice = 'La pièce jointe a bien été supprimée.' end diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index 00ec3a559..27bda0eb8 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -40,7 +40,7 @@ class Champs::PieceJustificativeChamp < Champ end if errors.present? - piece_justificative_file.purge + piece_justificative_file.purge_later end errors From f833f57e457debf323ef240aa26d0a97fc48d3d4 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 21 May 2019 11:42:21 +0200 Subject: [PATCH 2/2] Add PurgeUnattachedBlobsJob --- README.md | 1 + app/jobs/purge_unattached_blobs_job.rb | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 app/jobs/purge_unattached_blobs_job.rb diff --git a/README.md b/README.md index ed501dad8..3590f6833 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ En local, un utilisateur de test est créé automatiquement, avec les identifian Administrateurs::ActivateBeforeExpirationJob.set(cron: "0 8 * * *").perform_later WarnExpiringDossiersJob.set(cron: "0 0 1 * *").perform_later GestionnaireEmailNotificationJob.set(cron: "0 10 * * 1,2,3,4,5,6").perform_later + PurgeUnattachedBlobsJob.set("0 0 * * *").perform_later ### Voir les emails envoyés en local diff --git a/app/jobs/purge_unattached_blobs_job.rb b/app/jobs/purge_unattached_blobs_job.rb new file mode 100644 index 000000000..fb5d5804e --- /dev/null +++ b/app/jobs/purge_unattached_blobs_job.rb @@ -0,0 +1,9 @@ +class PurgeUnattachedBlobsJob < ApplicationJob + queue_as :cron + + def perform(*args) + ActiveStorage::Blob.unattached + .where('active_storage_blobs.created_at < ?', 24.hours.ago) + .find_each(&:purge_later) + end +end