diff --git a/lib/delayed/job_groups/railtie.rb b/lib/delayed/job_groups/railtie.rb new file mode 100644 index 0000000..7a7a210 --- /dev/null +++ b/lib/delayed/job_groups/railtie.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Delayed + module JobGroups + class Railtie < ::Rails::Railtie + config.after_initialize do + Delayed::Backend::ActiveRecord::Job.include(Delayed::JobGroups::JobExtensions) + end + end + end +end diff --git a/lib/delayed_job_groups_plugin.rb b/lib/delayed_job_groups_plugin.rb index 7d6bcc1..1c69651 100644 --- a/lib/delayed_job_groups_plugin.rb +++ b/lib/delayed_job_groups_plugin.rb @@ -11,6 +11,15 @@ require 'delayed/job_groups/yaml_loader' require 'delayed/job_groups/version' -Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::JobGroups::JobExtensions) +if defined?(Delayed::Backend::ActiveRecord) + if defined?(Rails::Railtie) + # Postpone initialization to railtie for correct order + require 'delayed/job_groups/railtie' + else + # Do the same as in the railtie + Delayed::Backend::ActiveRecord::Job.include(Delayed::JobGroups::JobExtensions) + end +end + Delayed::Worker.plugins << Delayed::JobGroups::Plugin