-
-
Notifications
You must be signed in to change notification settings - Fork 529
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
Introduce suspenders:jobs
generator
#1147
Conversation
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.
Thank you for taking this one on! I recognize this is a draft, but wanted to share some initial thoughts.
89ceac7
to
35ad96e
Compare
module ActiveJob | ||
module Logging | ||
class EnqueueLogSubscriber < LogSubscriber | ||
define_method :enqueue, instance_method(:enqueue) |
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.
I think this doesn't work in Rails 7.1.
Have you tested the generator "manually" on a new application?
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.
Thank you for the comment @crackofdusk ! It has made me investigate more and try the generator in a new app.
It looks like it’s working, but please let me know if you think otherwise.
I took the following steps to test it:
-
I created a new Rails 7.1.2 App
-
I added the generator to this app.
-
I added the template
active_job.rb
-
I ran in my terminal
bin/rails generate jobs
-
This has generated the following
gemfile sidekiq run bundle install from "." Bundle complete! 16 Gemfile dependencies, 85 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed. create config/initializers/active_job.rb Add default Procfile.dev create Procfile.dev
-
I can see the
sidekiq
gem in the Gemfile, theactive_job
file in initializers, and theProcfile
with the expected configuration. -
Then I create a job -
MyJob
I modified the initializer to:
require "active_job/logging"
require "active_job/log_subscriber"
# ActiveSupport::Notifications.unsubscribe("enqueue.active_job")
Rails.logger.info "Custom Active Job initializer is running"
module ActiveJob
module Logging
class EnqueueLogSubscriber < LogSubscriber
puts "ActiveJob::Logging::EnqueueLogSubscriber"
puts "I'm running"
define_method :enqueue, instance_method(:enqueue)
end
end
end
ActiveJob::Logging::EnqueueLogSubscriber.attach_to(:active_job)
I ran rails console
and I can see:
ActiveJob::Logging::EnqueueLogSubscriber
I'm running
and when I run the job MyJob.perform_later
, I can see in the logs:
Custom Active Job initializer is running
[ActiveJob] Enqueued MyJob (Job ID: 02a76977-c7a1-47c6-8366-787c097b83f4) to Sidekiq(default)
[ActiveJob] ↳ (irb):1:in `<main>'
[ActiveJob] Enqueued MyJob (Job ID: 02a76977-c7a1-47c6-8366-787c097b83f4)
Let me know what you think 😃
I added the gem from this branch into the new rails app using:
group :development, :test do
gem "suspenders", github: "thoughtbot/suspenders", branch: "suspenders-3-0-0-jobs-generator"
end
and run the generator.
bin/rails g suspenders:jobs
I got the same output as above.
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.
Thank you for testing! I had a problem with this patch when upgrading an application from Rails 7.0 to 7.1. The error could have been caused by something else. For me it's enough if this generator works a new Rails application.
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.
We'll also want to update the README
and NEWS
too, before merging.
24138dd
to
1717fd0
Compare
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.
Great work. Thank you!
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.
Here's the commit that introduced this for context.
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.
Thank you 🙂
Ports the existing generator to Suspenders 3.0.
69c3190
to
bab99b1
Compare
Follow-up to #1147 The [introduction][] of `config/initializers/active_job.rb` was rendered obsolete by [rails/rails#43390][]. Additionally, the following Rails 7 defaults match the [existing configuration][], so there is no need to redeclare them. ```ruby Rails.application.config.action_mailer.deliver_later_queue_name => nil Rails.application.config.action_mailbox.queues.routing => nil Rails.application.config.active_storage.queues.analysis => nil Rails.application.config.active_storage.queues.purge => nil Rails.application.config.active_storage.queues.mirror => nil ``` This is relevant because the next release of Suspenders will only support `rails >= 7.0`. [introduction]: 38b530c [rails/rails#43390]: rails/rails#43390 [existing configuration]: https://github.com/thoughtbot/suspenders/blob/bd40e33a585891afba380a7884284f5accc003cf/lib/suspenders/generators/jobs_generator.rb#L19-L23
Ports the existing generator to Suspenders 3.0.
Follow-up to #1147 The [introduction][] of `config/initializers/active_job.rb` was rendered obsolete by [rails/rails#43390][]. Additionally, the following Rails 7 defaults match the [existing configuration][], so there is no need to redeclare them. ```ruby Rails.application.config.action_mailer.deliver_later_queue_name => nil Rails.application.config.action_mailbox.queues.routing => nil Rails.application.config.active_storage.queues.analysis => nil Rails.application.config.active_storage.queues.purge => nil Rails.application.config.active_storage.queues.mirror => nil ``` This is relevant because the next release of Suspenders will only support `rails >= 7.0`. [introduction]: 38b530c [rails/rails#43390]: rails/rails#43390 [existing configuration]: https://github.com/thoughtbot/suspenders/blob/bd40e33a585891afba380a7884284f5accc003cf/lib/suspenders/generators/jobs_generator.rb#L19-L23
Ports the existing generator to Suspenders 3.0.