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

Allow a worker to be used for multiple queues. #153

Closed
wants to merge 2 commits into from

Conversation

Senjai
Copy link
Contributor

@Senjai Senjai commented Nov 6, 2015

This allows workers to be used for multiple queues. There may be several queues from several applications, where the process logic is 100% the same. To handle this currently you need one class per queue which violates dry if we could simply have Shoryuken use the same class for each queue.

An example of where this is a requirement would be a failures interface for several applications based on SQS. Each application has its' own dead letter queue, but you can use a common interface to represent and store failures from each dead letter queue.

Additionally, if you work with queues outside of your codebase, the segregation may work for a third party, but may be indifferent in your application, so processing them as separate flows would not make sense.

This deprecates the queue parameter in favour of a queues parameter and allows for a soft cutover to the new logic.

expect(GlobalDefaultsTestWorker.get_shoryuken_options['batch']).to eq false
it "still contains configuration not explicitly changed" do
subject
expect(dummy_worker.get_shoryuken_options["queues"]).to include("randomqueues")

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

@Senjai
Copy link
Contributor Author

Senjai commented Nov 6, 2015

Could we change the hound configuration to not care about meaningless things?

@Senjai
Copy link
Contributor Author

Senjai commented Nov 6, 2015

Failure unrelated.

@Senjai
Copy link
Contributor Author

Senjai commented Nov 16, 2015

@phstc Any comment on this one?

@phstc
Copy link
Collaborator

phstc commented Nov 18, 2015

@Senjai I still need to test it locally. But currently shoryuken supports multiple queues for the same worker:

MyWorker.perform_async('Pablo', queue: 'important') # will queue to the 'important' queue

How the shoryuken.yml would look like with your change? Your change is to define multiple queues in there? Could you send me a code snippet showing how to use your changes?

Could we change the hound configuration to not care about meaningless things?

I prefer to keep the code base concise, keeping the same formatting for all code. The motivation on that is to avoid distractions while maintaining the code. Could you review those houndci feedbacks?

@Senjai
Copy link
Contributor Author

Senjai commented Nov 18, 2015

@phstc I don't use the workers like that. Our worker application runs standalone, and doesn't run with rails.

class MyWorker
  include Shoryuken::Worker
  shoryuken_options queues: ['queue1', 'queue2']
end

This was previously not supported. Shoryuken.yml would not change as it defines what queues to listen to, not what workers to use. This simply registers the worker twice, once for each queue.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

This goes against the grain of most style guides, and the argument of single quotes being more performant is a moot one.

From the github style guide:

Use double-quoted strings. Interpolation and escaped characters will always work without a delimiter change, and ' is a lot more common than " in string literals.

In CanCanCan I don't really care which literal contributors use, I'd rather have the contributor focus on providing good solutions rather than worry about what quotes they use. If you feel strongly about it, I can change it for this PR.

@phstc
Copy link
Collaborator

phstc commented Nov 18, 2015

@Senjai I see your use case, I will test it locally this week, tks 🍻

This goes against the grain of most style guides, and the argument of single quotes being more performant is a moot one.

My motivation on single vs double quotes is not about performance, it's more about being consistent, and to do that, we need to pick one style:

https://github.com/bbatsov/ruby-style-guide
(Option A) Prefer single-quoted strings when you don't need string interpolation or special symbols such as \t, \n, ', etc.
(Option B) Prefer double-quotes unless your string literal contains " or escape characters you want to suppress.

I chose Option A.

If you feel strongly about it, I can change it for this PR.

Could you? ❤️

Other projects do the same about code convention.

This allows a worker to be used for more than one queue. Ocassionaly,
logic for several queues is the same, creating a class for each queue is
cumbersome and can be avoided.

shoryuken_options auto_delete: true
it 'overrides default configuration' do
expect{subject}.to change{dummy_worker.get_shoryuken_options['auto_delete']}.

Choose a reason for hiding this comment

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

Space missing to the left of {.
Space missing inside {.
Space missing inside }.


it "registers the result of a block queue" do
expect(Shoryuken).to receive(:register_worker).
with("block_queue", dummy_worker)

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

@Senjai
Copy link
Contributor Author

Senjai commented Nov 20, 2015

@phstc Bumped

end


Choose a reason for hiding this comment

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

Extra blank line detected.

@phstc
Copy link
Collaborator

phstc commented Dec 13, 2015

@Senjai I still think that multiple queues per worker is an edge case, for instance Sidekiq does not support it. So I wouldn't have queues instead of queue as a shoryuken_options.

While I'm still thinking about it, I've also created a new PR #164 which allows queue to be a string, proc or array: https://github.com/phstc/shoryuken/pull/164/files#diff-bd2ce13e624208d2b1e127de91c67eaeR71 - wdyt?

@phstc phstc closed this Dec 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants