-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Railtie to delayed_job_active_record
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
Showing
2 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |