Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add delay option into Shoryuken.add_group #543

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/shoryuken/environment_loader.rb
Expand Up @@ -130,7 +130,7 @@ def parse_queues
end

Shoryuken.options[:groups].to_a.each do |group, options|
Shoryuken.add_group(group, options.fetch(:concurrency, 25))
Shoryuken.add_group(group, options.fetch(:concurrency, 25), delay: options.fetch(:delay, 0))
options[:queues].to_a.each do |queue, weight|
parse_queue(queue, weight, group)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/shoryuken/polling/base.rb
Expand Up @@ -60,7 +60,11 @@ def ==(other)
private
Copy link
Author

Choose a reason for hiding this comment

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

I made delay public and wrote some tests for it on each polling strategy.


def delay
Shoryuken.options[:delay].to_f
if name == 'default'
Shoryuken.options[:delay].to_f
else # allow delay settings per group
Shoryuken.options[:groups].to_h[name]).to_h[:delay]
phstc marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
Expand Down
25 changes: 24 additions & 1 deletion spec/shoryuken/environment_loader_spec.rb
Expand Up @@ -4,7 +4,7 @@
RSpec.describe Shoryuken::EnvironmentLoader do
subject { described_class.new({}) }

describe '#parse_queues' do
describe '#parse_queues loads default queues' do
before do
allow(subject).to receive(:load_rails)
allow(subject).to receive(:prefix_active_job_queue_names)
Expand All @@ -22,6 +22,29 @@
end
end

describe '#parse_queues includes delay per groups' do
before do
allow(subject).to receive(:load_rails)
allow(subject).to receive(:prefix_active_job_queue_names)
allow(subject).to receive(:require_workers)
allow(subject).to receive(:validate_queues)
allow(subject).to receive(:validate_workers)
allow(subject).to receive(:patch_deprecated_workers)
end

specify do
Shoryuken.options[:queues] = ['queue1', 'queue2'] # default queues
Shoryuken.options[:groups] = [[ 'custom', { queues: ['queue3'], delay: 25 }]]
subject.load

expect(Shoryuken.groups['default'][:queues]).to eq(%w[queue1 queue2])
expect(Shoryuken.groups['default'][:delay]).to eq(0)
expect(Shoryuken.groups['custom'][:queues]).to eq(%w[queue3])
expect(Shoryuken.groups['custom'][:delay]).to eq(25)
end
end


describe '#prefix_active_job_queue_names' do
before do
allow(subject).to receive(:load_rails)
Expand Down