-
Notifications
You must be signed in to change notification settings - Fork 407
ActiveJob: support per-worker queue name configuration #334
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
ActiveJob: support per-worker queue name configuration #334
Conversation
- Update Support::Backends.enqueue_active_job method - Add tests - Update README.md
queue_name -> backend_name
Addresses lardawge#223 Partially addresses lardawge#162
- Fix several typos - Improve styling
| mock_module.enqueue_for_backend(MockActiveJob, *args) | ||
| end | ||
|
|
||
| describe 'queue name configuration' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I am leaning into integration specs vs mocking/stubbing. I find it harder to maintain, and it relies on mocks being set up correctly as well as library apis never changing... which is never the case.
I am happy to merge this PR if you can find a way to use the integration specs.
- Add columns to :user and :admin - Setup models, uploader and jobs
- Revisit the configuration instructions - Use <details> for visual order - Add some formatting
|
@lardawge I found several problems in my changes while working on the integration specs, so I had to dig deeper into this gem and |
|
Thanks for getting this close. Much appreciated. There are a couple of things that seem to have happened, which are adding to the complexity of testing. The initial idea was to offload any switching of backends to separate test runs using env vars so that we didn't have to do any hackery to test the different scenarios, AJ vs Sidekiq. That means the tests themselves must be agnostic to what needs to be loaded, and they should not care. All loading of appropriate files occurs in the config method, based on the backend. There is no scenario where one would need to switch back and forth between AR and Sidekiq in a real-world situation. I understand the problem is trying to test custom workers. That is leading to an issue where the gymnastics need to happen. Another approach might be to require the files in rails_helper.rb when you know what backend is being tested. That should drastically simplify the approach to testing. Let me know if that makes sense. |
Excluding SpecsI found a way to exclude certain specs based on the ENV variable. # spec/spec_helper.rb
RSpec.configure do |c|
c.include WarningSuppression
if ENV['BACKEND'] == 'active_job'
c.exclude_pattern = 'spec/integrations/sidekiq/*'
elsif ENV['BACKEND'] == 'sidekiq'
c.exclude_pattern = 'spec/integrations/active_job/*'
end
endFailing Tests!However, with this I started getting red tests! ReasonIt happens during
A Fix?I can fix this with several approaches:
All these options smell, so I'd love to know what's your opinion here @lardawge. |
|
I spent some time this morning taking a fresh stab at this feature. It is clear, or I believe this was attempted using AI (correct me if I'm wrong). It made a hash of it. I could not make heads or tails of the spec files, which I use and expect to be clear, given that it is documentation. There are so many changes in this PR that it was easier for me to tackle it separately. The main challenges are that testing needs to be isolated with and without AJ. As you experienced, referencing files that are not loaded when running I still am not 100% happy with the setup. For example, I am testing a config, but skipping the part about the actual config because of the limitations of Rails initializers and the inability to easily reload the app. I think it is fine since we know the initializer works and have other tests to prove it. We are then only testing the different scenarios... either way, take a look and let me know if it makes sense. PR #335 |
- Conditionally exclude AJ or Sidekiq enqueuing tests - Fix Rails 8.1 `to_time` DEPRECATION WARNING
|
The spec files are just covering all possible permutations on 3 levels for each backend type: global queue configuration, worker queue configuration and different corner-cases like passing I also described ActiveJob's Sorry for the many changes. I don't use AI, it frightens me. |
|
I am closing this in favor of the less verbose version #335. I appreciate this PR as well as the effort put into it. |

Reasoning
Sometimes it's necessary to be able to push some overridden worker jobs to a queue different from globally defined.
Current implementation of
Support::Backends.enqueue_active_jobmethod doesn't allow for specifying a queue name for a dedicated worker – theActiveJob'squeue_assetting gets ignored in favor of the globally-configured queue name:Strategy
ActiveJobuses.setmethod to change the queueing settings.With the rest, I mimicked the
Support::Backends.enqueue_sidekiqlogics:defaultornilqueue names are ignored for consistency, however, it's possible to force thedefaultas queue name by usingqueue_asmethod with a block:Tests
Added 8 test cases, 4 of which are really related to the changes.
Extras
Also, this PR:
README.md.backends_spec.rb.sidekiqqueue name configuration example to theREADME.md.README.md.