Introduce suspenders:jobs generator#1147
Conversation
stevepolitodesign
left a comment
There was a problem hiding this comment.
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.
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.
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
sidekiqgem in the Gemfile, theactive_jobfile in initializers, and theProcfilewith 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.
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.
stevepolitodesign
left a comment
There was a problem hiding this comment.
We'll also want to update the README and NEWS too, before merging.
24138dd to
1717fd0
Compare
stevepolitodesign
left a comment
There was a problem hiding this comment.
Great work. Thank you!
There was a problem hiding this comment.
Here's the commit that introduced this for context.
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.