aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app/jobs/active_storage/mirror_job.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2019-05-22 15:07:35 -0400
committerGitHub <noreply@github.com>2019-05-22 15:07:35 -0400
commitd5a2f7ec148726d7547e367d7a968e3b4be9b509 (patch)
tree1818959b09d3bdde9b43440fe5ca8fa402984ec3 /activestorage/app/jobs/active_storage/mirror_job.rb
parentff34f78248e367fdc7d59b42b37610427f7339c8 (diff)
downloadrails-d5a2f7ec148726d7547e367d7a968e3b4be9b509.tar.gz
rails-d5a2f7ec148726d7547e367d7a968e3b4be9b509.tar.bz2
rails-d5a2f7ec148726d7547e367d7a968e3b4be9b509.zip
Mirror direct uploads
Diffstat (limited to 'activestorage/app/jobs/active_storage/mirror_job.rb')
-rw-r--r--activestorage/app/jobs/active_storage/mirror_job.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activestorage/app/jobs/active_storage/mirror_job.rb b/activestorage/app/jobs/active_storage/mirror_job.rb
new file mode 100644
index 0000000000..e34faedb56
--- /dev/null
+++ b/activestorage/app/jobs/active_storage/mirror_job.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+# Provides asynchronous mirroring of directly-uploaded blobs.
+class ActiveStorage::MirrorJob < ActiveStorage::BaseJob
+ queue_as { ActiveStorage.queues[:mirror] }
+
+ discard_on ActiveStorage::FileNotFoundError
+ retry_on ActiveStorage::IntegrityError, attempts: 10, wait: :exponentially_longer
+
+ def perform(key, checksum:)
+ ActiveStorage::Blob.service.try(:mirror, key, checksum: checksum)
+ end
+end