mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Permit sending Active Storage purge and analysis jobs to separate queues
This commit is contained in:
parent
0dec2b5aa3
commit
ed51351536
7 changed files with 40 additions and 5 deletions
|
@ -1,3 +1,14 @@
|
|||
* Replace `config.active_storage.queue` with two options that indicate which
|
||||
queues analysis and purge jobs should use, respectively:
|
||||
|
||||
* `config.active_storage.queues.analysis`
|
||||
* `config.active_storage.queues.purge`
|
||||
|
||||
`config.active_storage.queue` is preferred over the new options when it's
|
||||
set, but it is deprecated and will be removed in Rails 6.1.
|
||||
|
||||
*George Claghorn*
|
||||
|
||||
* Permit generating variants of TIFF images.
|
||||
|
||||
*Luciano Sousa*
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
# Provides asynchronous analysis of ActiveStorage::Blob records via ActiveStorage::Blob#analyze_later.
|
||||
class ActiveStorage::AnalyzeJob < ActiveStorage::BaseJob
|
||||
queue_as { ActiveStorage.queues[:analysis] }
|
||||
|
||||
retry_on ActiveStorage::IntegrityError, attempts: 10, wait: :exponentially_longer
|
||||
|
||||
def perform(blob)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActiveStorage::BaseJob < ActiveJob::Base
|
||||
queue_as { ActiveStorage.queue }
|
||||
end
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
# Provides asynchronous purging of ActiveStorage::Blob records via ActiveStorage::Blob#purge_later.
|
||||
class ActiveStorage::PurgeJob < ActiveStorage::BaseJob
|
||||
queue_as { ActiveStorage.queues[:purge] }
|
||||
|
||||
discard_on ActiveRecord::RecordNotFound
|
||||
retry_on ActiveRecord::Deadlocked, attempts: 10, wait: :exponentially_longer
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ module ActiveStorage
|
|||
|
||||
mattr_accessor :logger
|
||||
mattr_accessor :verifier
|
||||
mattr_accessor :queue
|
||||
mattr_accessor :queues, default: {}
|
||||
mattr_accessor :previewers, default: []
|
||||
mattr_accessor :analyzers, default: []
|
||||
mattr_accessor :variant_processor, default: :mini_magick
|
||||
|
|
|
@ -20,6 +20,7 @@ module ActiveStorage
|
|||
config.active_storage.previewers = [ ActiveStorage::Previewer::PopplerPDFPreviewer, ActiveStorage::Previewer::MuPDFPreviewer, ActiveStorage::Previewer::VideoPreviewer ]
|
||||
config.active_storage.analyzers = [ ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer ]
|
||||
config.active_storage.paths = ActiveSupport::OrderedOptions.new
|
||||
config.active_storage.queues = ActiveSupport::OrderedOptions.new
|
||||
|
||||
config.active_storage.variable_content_types = %w(
|
||||
image/png
|
||||
|
@ -61,7 +62,6 @@ module ActiveStorage
|
|||
initializer "active_storage.configs" do
|
||||
config.after_initialize do |app|
|
||||
ActiveStorage.logger = app.config.active_storage.logger || Rails.logger
|
||||
ActiveStorage.queue = app.config.active_storage.queue
|
||||
ActiveStorage.variant_processor = app.config.active_storage.variant_processor || :mini_magick
|
||||
ActiveStorage.previewers = app.config.active_storage.previewers || []
|
||||
ActiveStorage.analyzers = app.config.active_storage.analyzers || []
|
||||
|
@ -117,6 +117,20 @@ module ActiveStorage
|
|||
end
|
||||
end
|
||||
|
||||
initializer "active_storage.queues" do
|
||||
config.after_initialize do |app|
|
||||
if queue = app.config.active_storage.queue
|
||||
ActiveSupport::Deprecation.warn \
|
||||
"config.active_storage.queue is deprecated and will be removed in Rails 6.1. " \
|
||||
"Set config.active_storage.queues.purge and config.active_storage.queues.analysis instead."
|
||||
|
||||
ActiveStorage.queues = { purge: queue, analysis: queue }
|
||||
else
|
||||
ActiveStorage.queues = app.config.active_storage.queues || {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
initializer "active_storage.reflection" do
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
include Reflection::ActiveRecordExtensions
|
||||
|
|
|
@ -843,10 +843,16 @@ normal Rails server.
|
|||
* `config.active_storage.content_types_to_serve_as_binary` accepts an array of strings indicating the content types that Active Storage will always serve as an attachment, rather than inline. The default is `%w(text/html
|
||||
text/javascript image/svg+xml application/postscript application/x-shockwave-flash text/xml application/xml application/xhtml+xml)`.
|
||||
|
||||
* `config.active_storage.queue` can be used to set the name of the Active Job queue used to perform jobs like analyzing the content of a blob or purging a blog.
|
||||
* `config.active_storage.queues.analysis` accepts a symbol indicating the Active Job queue to use for analysis jobs. When this option is `nil`, analysis jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`).
|
||||
|
||||
```ruby
|
||||
config.active_storage.queues.analysis = :low_priority
|
||||
```
|
||||
|
||||
* `config.active_storage.queues.purge` accepts a symbol indicating the Active Job queue to use for purge jobs. When this option is `nil`, purge jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`).
|
||||
|
||||
```ruby
|
||||
config.active_storage.queue = :low_priority
|
||||
config.active_storage.queues.purge = :low_priority
|
||||
```
|
||||
|
||||
* `config.active_storage.logger` can be used to set the logger used by Active Storage. Accepts a logger conforming to the interface of Log4r or the default Ruby Logger class.
|
||||
|
@ -870,6 +876,7 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
|
|||
|
||||
The default is `/rails/active_storage`
|
||||
|
||||
|
||||
### Configuring a Database
|
||||
|
||||
Just about every Rails application will interact with a database. You can connect to the database by setting an environment variable `ENV['DATABASE_URL']` or by using a configuration file called `config/database.yml`.
|
||||
|
|
Loading…
Reference in a new issue