Skip to content

Commit

Permalink
Add Railtie to delayed_job_active_record
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yuki24 committed May 1, 2015
1 parent 270b06e commit a95ead2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/delayed/backend/active_record/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Delayed
module Backend
module ActiveRecord
class Railtie < ::Rails::Railtie
initializer 'delayed_job_active_record' do |_app|
ActiveSupport.on_load(:active_record) do
require "delayed/backend/active_record"
Delayed::Worker.backend = :active_record
end
end
end
end
end
end
11 changes: 8 additions & 3 deletions lib/delayed_job_active_record.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require "active_record"
require "delayed_job"
require "delayed/backend/active_record"

Delayed::Worker.backend = :active_record
if defined?(Rails)
require "delayed/backend/active_record/railtie"
else
require "active_record"
require "delayed/backend/active_record"

Delayed::Worker.backend = :active_record
end

0 comments on commit a95ead2

Please sign in to comment.