Merge pull request #3891 from tchak/purge-orphaned-blobs

Purge unattached blobs
This commit is contained in:
Paul Chavard 2019-05-21 14:18:14 +02:00 committed by GitHub
commit b55fae440b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -40,7 +40,7 @@ class Champs::PieceJustificativeChamp < Champ
end
if errors.present?
piece_justificative_file.purge
piece_justificative_file.purge_later
end
errors