From 25743317b17489c5e0a48706f0ef02b2f65321c2 Mon Sep 17 00:00:00 2001 From: Thomas Hoen Date: Sun, 3 Jan 2021 10:53:02 -0500 Subject: [PATCH 1/4] Defer include until after initialization as that is when delayed_job_active_record now instantiates --- .../job_groups/backend/active_record/railtie.rb | 13 +++++++++++++ lib/delayed_job_groups_plugin.rb | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 lib/delayed/job_groups/backend/active_record/railtie.rb diff --git a/lib/delayed/job_groups/backend/active_record/railtie.rb b/lib/delayed/job_groups/backend/active_record/railtie.rb new file mode 100644 index 0000000..e1bd783 --- /dev/null +++ b/lib/delayed/job_groups/backend/active_record/railtie.rb @@ -0,0 +1,13 @@ +module Delayed + module JobGroups + module Backend + module ActiveRecord + class Railtie < ::Rails::Railtie + config.after_initialize do + Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::JobGroups::JobExtensions) + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/delayed_job_groups_plugin.rb b/lib/delayed_job_groups_plugin.rb index 7d6bcc1..fe7ccf7 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/backend/active_record/railtie' + else + # Do the same as in the railtie + Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::JobGroups::JobExtensions) + end +end + Delayed::Worker.plugins << Delayed::JobGroups::Plugin From 5005b20b1e5ee8a2a319982661df94834ffa058c Mon Sep 17 00:00:00 2001 From: Thomas Hoen Date: Wed, 6 Jan 2021 17:47:18 -0500 Subject: [PATCH 2/4] Move railtie.rb to be consistent with other classes in the project. Update to use Ruby 2.5 include method. RuboCop! --- .../job_groups/backend/active_record/railtie.rb | 13 ------------- lib/delayed/job_groups/railtie.rb | 11 +++++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) delete mode 100644 lib/delayed/job_groups/backend/active_record/railtie.rb create mode 100644 lib/delayed/job_groups/railtie.rb diff --git a/lib/delayed/job_groups/backend/active_record/railtie.rb b/lib/delayed/job_groups/backend/active_record/railtie.rb deleted file mode 100644 index e1bd783..0000000 --- a/lib/delayed/job_groups/backend/active_record/railtie.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Delayed - module JobGroups - module Backend - module ActiveRecord - class Railtie < ::Rails::Railtie - config.after_initialize do - Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::JobGroups::JobExtensions) - end - end - end - end - end -end \ No newline at end of file diff --git a/lib/delayed/job_groups/railtie.rb b/lib/delayed/job_groups/railtie.rb new file mode 100644 index 0000000..670f811 --- /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 \ No newline at end of file From d819d4dc1cbfa86836319e551e94798d0e1efa27 Mon Sep 17 00:00:00 2001 From: Thomas Hoen Date: Wed, 6 Jan 2021 17:48:52 -0500 Subject: [PATCH 3/4] Update require statement to match new location of railtie.rb. Update to use ruby 2.5 include --- lib/delayed_job_groups_plugin.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/delayed_job_groups_plugin.rb b/lib/delayed_job_groups_plugin.rb index fe7ccf7..1c69651 100644 --- a/lib/delayed_job_groups_plugin.rb +++ b/lib/delayed_job_groups_plugin.rb @@ -14,10 +14,10 @@ if defined?(Delayed::Backend::ActiveRecord) if defined?(Rails::Railtie) # Postpone initialization to railtie for correct order - require 'delayed/job_groups/backend/active_record/railtie' + require 'delayed/job_groups/railtie' else # Do the same as in the railtie - Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::JobGroups::JobExtensions) + Delayed::Backend::ActiveRecord::Job.include(Delayed::JobGroups::JobExtensions) end end From 3c92b72b622ed393bdd2f6b206cab7dc24d11fc6 Mon Sep 17 00:00:00 2001 From: Thomas Hoen Date: Wed, 6 Jan 2021 17:56:50 -0500 Subject: [PATCH 4/4] Adds missing newline --- lib/delayed/job_groups/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/delayed/job_groups/railtie.rb b/lib/delayed/job_groups/railtie.rb index 670f811..7a7a210 100644 --- a/lib/delayed/job_groups/railtie.rb +++ b/lib/delayed/job_groups/railtie.rb @@ -8,4 +8,4 @@ class Railtie < ::Rails::Railtie end end end -end \ No newline at end of file +end