diff options
Diffstat (limited to 'lib/active_vault')
-rw-r--r-- | lib/active_vault/attached/macros.rb | 12 | ||||
-rw-r--r-- | lib/active_vault/attachment.rb | 4 | ||||
-rw-r--r-- | lib/active_vault/blob.rb | 1 | ||||
-rw-r--r-- | lib/active_vault/purge_job.rb | 9 |
4 files changed, 21 insertions, 5 deletions
diff --git a/lib/active_vault/attached/macros.rb b/lib/active_vault/attached/macros.rb index 8cc84a95a9..1b95c14c9c 100644 --- a/lib/active_vault/attached/macros.rb +++ b/lib/active_vault/attached/macros.rb @@ -1,15 +1,23 @@ module ActiveVault::Attached::Macros - def has_one_attached(name) + def has_one_attached(name, dependent: :purge_later) define_method(name) do instance_variable_get("@active_vault_attached_#{name}") || instance_variable_set("@active_vault_attached_#{name}", ActiveVault::Attached::One.new(name, self)) end + + if dependent == :purge_later + before_destroy { public_send(name).purge_later } + end end - def has_many_attached(name) + def has_many_attached(name, dependent: :purge_later) define_method(name) do instance_variable_get("@active_vault_attached_#{name}") || instance_variable_set("@active_vault_attached_#{name}", ActiveVault::Attached::Many.new(name, self)) end + + if dependent == :purge_later + before_destroy { public_send(name).purge_later } + end end end diff --git a/lib/active_vault/attachment.rb b/lib/active_vault/attachment.rb index 1c96dabe31..549a734d68 100644 --- a/lib/active_vault/attachment.rb +++ b/lib/active_vault/attachment.rb @@ -23,4 +23,8 @@ class ActiveVault::Attachment < ActiveRecord::Base blob.purge destroy end + + def purge_later + ActiveVault::PurgeJob.perform_later(self) + end end diff --git a/lib/active_vault/blob.rb b/lib/active_vault/blob.rb index e2a6582e9f..a232ca5c1a 100644 --- a/lib/active_vault/blob.rb +++ b/lib/active_vault/blob.rb @@ -1,5 +1,6 @@ require "active_vault/site" require "active_vault/filename" +require "active_vault/purge_job" # Schema: id, key, filename, content_type, metadata, byte_size, checksum, created_at class ActiveVault::Blob < ActiveRecord::Base diff --git a/lib/active_vault/purge_job.rb b/lib/active_vault/purge_job.rb index d7634af2bb..b68eb370bb 100644 --- a/lib/active_vault/purge_job.rb +++ b/lib/active_vault/purge_job.rb @@ -1,7 +1,10 @@ +require "active_job" + class ActiveVault::PurgeJob < ActiveJob::Base - retry_on ActiveVault::StorageException + # FIXME: Limit this to a custom ActiveVault error + retry_on StandardError - def perform(blob) - blob.purge + def perform(attachment_or_blob) + attachment_or_blob.purge end end |