Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow configuration of Active Job queue name #707

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ Chewy.strategy(:sidekiq) do
end
```

The default queue name is `chewy`, you can customize it in settings: `sidekiq.queue_name`
```
Chewy.settings[:sidekiq] = {queue: :low}
```

#### `:active_job`

This does the same thing as `:atomic`, but using ActiveJob. This will inherit the ActiveJob configuration settings including the `active_job.queue_adapter` setting for the environment. Patch `Chewy::Strategy::ActiveJob::Worker` for index updates improving.
Expand All @@ -688,6 +693,11 @@ Chewy.strategy(:active_job) do
end
```

The default queue name is `chewy`, you can customize it in settings: `active_job.queue_name`
```
Chewy.settings[:active_job] = {queue: :low}
```

#### `:shoryuken`

This does the same thing as `:atomic`, but asynchronously using shoryuken. Patch `Chewy::Strategy::Shoryuken::Worker` for index updates improving.
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/strategy/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Strategy
#
class ActiveJob < Atomic
class Worker < ::ActiveJob::Base
queue_as :chewy
queue_as { Chewy.settings.dig(:active_job, :queue) || 'chewy' }

def perform(type, ids, options = {})
options[:refresh] = !Chewy.disable_refresh_async if Chewy.disable_refresh_async
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/strategy/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def leave
private

def sidekiq_queue
Chewy.settings.fetch(:sidekiq, {})[:queue] || 'chewy'
Chewy.settings.dig(:sidekiq, :queue) || 'chewy'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by improvement

end
end
end
Expand Down
17 changes: 15 additions & 2 deletions spec/chewy/strategy/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

if defined?(::ActiveJob)
describe Chewy::Strategy::ActiveJob do
around { |example| Chewy.strategy(:bypass) { example.run } }
around do |example|
active_job_settings = Chewy.settings[:active_job]
Chewy.settings[:active_job] = {queue: 'low'}
Chewy.strategy(:bypass) { example.run }
Chewy.settings[:active_job] = active_job_settings
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making the tests order-independent

end
before(:all) do
::ActiveJob::Base.logger = Chewy.logger
end
Expand Down Expand Up @@ -36,7 +41,15 @@
end
enqueued_job = ::ActiveJob::Base.queue_adapter.enqueued_jobs.first
expect(enqueued_job[:job]).to eq(Chewy::Strategy::ActiveJob::Worker)
expect(enqueued_job[:queue]).to eq('chewy')
expect(enqueued_job[:queue]).to eq('low')
end

specify do
Chewy.strategy(:active_job) do
[city, other_city].map(&:save!)
end
enqueued_job = ::ActiveJob::Base.queue_adapter.enqueued_jobs.first
expect(enqueued_job[:queue]).to eq('low')
end

specify do
Expand Down
8 changes: 6 additions & 2 deletions spec/chewy/strategy/shoryuken_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
require 'aws-sdk-sqs'

describe Chewy::Strategy::Shoryuken do
around { |example| Chewy.strategy(:bypass) { example.run } }
around do |example|
shoryuken_settings = Chewy.settings[:shoryuken]
Chewy.settings[:shoryuken] = {queue: 'low'}
Chewy.strategy(:bypass) { example.run }
Chewy.settings[:shoryuken] = shoryuken_settings
end
before { ::Shoryuken.groups.clear }
before do
stub_model(:city) do
Expand All @@ -31,7 +36,6 @@
end

specify do
Chewy.settings[:shoryuken] = {queue: 'low'}
expect(Chewy::Strategy::Shoryuken::Worker).to receive(:perform_async)
.with(hash_including(type: 'CitiesIndex::City', ids: [city.id, other_city.id]), hash_including(queue: 'low'))
Chewy.strategy(:shoryuken) do
Expand Down
8 changes: 6 additions & 2 deletions spec/chewy/strategy/sidekiq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
require 'sidekiq/testing'

describe Chewy::Strategy::Sidekiq do
around { |example| Chewy.strategy(:bypass) { example.run } }
around do |example|
sidekiq_settings = Chewy.settings[:sidekiq]
Chewy.settings[:sidekiq] = {queue: 'low'}
Chewy.strategy(:bypass) { example.run }
Chewy.settings[:sidekiq] = sidekiq_settings
end
before { ::Sidekiq::Worker.clear_all }
before do
stub_model(:city) do
Expand All @@ -25,7 +30,6 @@
end

specify do
Chewy.settings[:sidekiq] = {queue: 'low'}
expect(::Sidekiq::Client).to receive(:push).with(hash_including('queue' => 'low')).and_call_original
::Sidekiq::Testing.inline! do
expect { [city, other_city].map(&:save!) }
Expand Down