-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
Inconsistencies in configuration settings #380
Comments
Hi @paul. Thank you for opening this issue. The simple answer is that configuration options should be defined before gem initialization in I myself try to organize all configuration inside of an initializer, but this is an area where I haven't figured out a good pattern to allow configuration to be defined after initialization (maybe having |
Hi @bensheldon, sorry its taken awhile to get back on this. I supposed I was confused about which options were "global", and which were "config", since |
That's my bad as gem author. Originally there was only the configuration accessors on My thinking at the moment is that everything should go into the Rails |
Hey! I'll use this issue to add my thoughts and our experiences from work as well (coming from #403 (comment)). In Rails 6.0 we added Starting with Rails 6.1 the first issue we encountered was that despite having a block like this in the intializer: # config/initializers/good_job.rb
Rails.application.configure do
config.active_job.queue_adapter = :good_job
end jobs were being executed using the Rails.application.config.active_job
=> {
:queue_adapter => :good_job
} but ActiveJob::Base.queue_adapter_name
=> "async" So the first option we moved to Anyway, I got curious and did some digging, but nothing that matched this behavior directly came up. Between Rails 6.0 and Rails 6.1 there were so many changes, nothing in particular popped out to me. However some issues on the Rails issue tracker seem like others have similar problems. rails/rails#36650 which links to other issues, but was closed because apparently it's a gem issue, not a Rails issue (which I don't think applies to GoodJob, since it ties in deeply into Rails configuration). However it was later clarified in a code comment in newly generated Rails apps that initializers are just too late to configure the Rails app, see rails/rails#34985. There's also rails/rails#37270 which I think is not directly related since according to some people it's still unresolved but it got me looking in the right direction. Also found rails/rails#40552 which feels like it should be related, but I couldn't tell. TL;DR:
So, we did what GoodJob's README says and put everything into |
@aried3r thank you for digging into it. I think you've linked out to the underlying issue perfectly:
I'm guessing that the change that happened in Rails 6.0/6.1 is that it introduces a loading dependency between ActiveRecord and ActiveJob, which means that ActiveJob is initialized even earlier than previous versions... and once ActiveJob is initialized, so is the adapter, which initializes GoodJob. I put in some logging to verify this: $ bin/rails s
RUNNING config/application.rb
=> Booting Puma
=> Rails 6.1.4.1 application starting in development
=> Run `bin/rails server --help` for more startup options
RUNNING config/environments/development.rb
INITIALIZING GoodJob::Adapter
RUNNING config/initializers/test.rb
RUNNING GoodJob Railtie config.after_initialize ...which explains it. The GoodJob::Adapter (which also initializes the Scheduler/Notifier/Cronmanager) is initialized before the application initializer, so none of that config is being used. It's arguable whether this is a workaround or working-as-intended, but I think this is our problem to solve at the moment:
...so I think there are two things we can do:
(and nervously, this makes me wonder whether |
My 2¢: Not a fan of 1. I guess its not up to you, but a Rails decision, but if suddenly every gem that hooks into rails has to be configured in I spot checked a few of the gems (omniauth, doorkeeper, activeadmin) plus some other AJ adapters (sidekiq, shoryuken), and they all have their own independent All that said, IMO, I think the preferred way for a well-integrated gem is what you outlined in 2: Let Rails handle the config, users define it in an initializer, then finally load Goodjob in an |
Thanks @paul. I agree that 1 is a distasteful workaround/warning. The practical challenge is that Rails may initialize the ActiveJob adapter (which would mean initializing GoodJob) during the boot phase, before the application initializers run. I think getting to 2 would mean initializing the Adapter in an inactive state, and moving all of these parts in good_job/lib/good_job/adapter.rb Lines 24 to 41 in 377cde2
Is anyone interested in working on that? |
Different config settings seem to behave differently based on how they're defined. I was trying to investigate why GoodJob wasn't preserving completed jobs, even though I have the setting enabled.
In
config/initializers/good_job.rb
, I have this:I'm enabling
preserve_job_records
, and its set when I examine the config, but when I look at the value on GoodJob, its not set:Other settings set the same way, like
execution_mode
, do what I expect and change how GoodJob runs. It seems it allowspreserve_job_records
to be set on config, but it has no effect. Alternatively, if I attempt to set all these values on GoodJob directly some of them (likeGoodJob.execution_mode = :extenal
) fail with "undefined method".It looks like GoodJob defines several
mattr_accessors
, but which settings are expected to be configured onconfig
, and which onGoodJob
directly?The text was updated successfully, but these errors were encountered: