collectiveidea / delayed_job_active_record

ActiveRecord backend integration for DelayedJob 3.0+
MIT License
346 stars 336 forks source link

Requiring delayed_job_active_record loads ActiveRecord::Base, which breaks Rails initialization #239

Open jpalermo opened 2 months ago

jpalermo commented 2 months ago

Some additional context in this Rails issue.

Essentially when you require delayed_job_active_record, since it has a class that inherits from ActiveRecord::Base, it causes the Rails class loader to initialize ActiveRecord which causes some parts of Rails to then not be configurable.

I was pointed to this guide which recommends using the on_load hooks of ActiveSupport:

ActiveSupport.on_load(:active_record) do
  DEFINE Delayed::Backend::ActiveRecord::Job < ::ActiveRecord::Base here
end

This will cause the block to get loaded after Rails initializes ActiveRecord