-
Notifications
You must be signed in to change notification settings - Fork 336
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
Add Railtie to delayed_job_active_record #106
Conversation
Explicitly requiring ActiveRecord models in `lib/delayed_job_active_record.rb` may result in losing custom configurations that are set in config/initializers on Rails. Let' use Railtie and ActiveSupport.on_load to set it up so that Delayed::Backend::ActiveRecord::Job model will respect arbitrary configs.
I was a bit concerned by the engine change but I don't think there's any downside to a railtie. 👍 |
My only concern with this is that AR might not load in dev mode. I am pretty sure the onload is trigger the first time ActiveRecord::Base is referenced and dev doesn't load anything until it is needed. Therefore DJ would not get setup until a model is actually used. |
We may be able to add an after_initialize to the Railtie to trigger a load |
This is working well for us, we only needed to add a |
I have a problem with this commit in production mode when running This is the error I get:
I've determined that the initializer runs but the active support module Delayed
module Backend
module ActiveRecord
class Railtie < ::Rails::Railtie
initializer 'delayed_job_active_record' do |_app|
puts 'This line is executed'
ActiveSupport.on_load(:active_record) do
puts 'This line is never executed'
require "delayed/backend/active_record"
Delayed::Worker.backend = :active_record
end
end
end
end
end
end The rake tasks work fine in development mode. |
If I modify the rake task to reference namespace :jobs do
desc 'Clear the delayed_job queue.'
task :clear => :environment do
ActiveRecord::Base
Delayed::Job.delete_all
end
end |
My workaround is to add a namespace :jobs do
task :reference_active_record_base do
ActiveRecord::Base
end
task clear: :reference_active_record_base
task work: :reference_active_record_base
end |
I'll rebase the commit later today. |
I should mention that I ran into the Rails 5 issue #128, and I am using the changes in this pull request through @lleger's fork mentioned in #128 (comment). |
Is there any chance that this will be resolved soon? I'm trying to upgrade a rails 4.2 project to rails 5.1, and I am hitting this problem because this gem is causing my I would try to use @lleger's fork, but:
Can we get this resolved so that we can use a Rails 5.0 project with Thank you |
We will be using the approach in #172 soon |
I'm following up on #105.
This changes
delayed_job_active_record
to useRailtie
andActiveSupport.on_load
to set it up on Rails so thatDelayed::Backend::ActiveRecord::Job
will respect arbitrary configs.