]> git.openstreetmap.org Git - rails.git/commitdiff
Monkey patch MailDeliveryJob to work with delayed_job under ruby 3
authorTom Hughes <tom@compton.nu>
Sat, 23 Jul 2022 11:03:51 +0000 (12:03 +0100)
committerTom Hughes <tom@compton.nu>
Sat, 23 Jul 2022 11:12:29 +0000 (12:12 +0100)
The delayed_job gem does not currently perserve keyword arguments
properly leading to errors when running under ruby 3 and try to run
a job that requires them.

This affects our deferred mail deliveries so we monkey patch the
mail delivery job to unpack the hash from the normal arguments and
use it to provide the expected keyword arguments.

https://github.com/collectiveidea/delayed_job/issues/1134

config/initializers/mail_delivery_job.rb [new file with mode: 0644]

diff --git a/config/initializers/mail_delivery_job.rb b/config/initializers/mail_delivery_job.rb
new file mode 100644 (file)
index 0000000..4bab200
--- /dev/null
@@ -0,0 +1,13 @@
+module OpenStreetMap
+  module ActionMailer
+    module MailDeliveryJob
+      def perform(mailer, mail_method, delivery_method, *args, **kwargs)
+        kwargs = args.pop if kwargs.empty? && args.last.is_a?(Hash)
+
+        super(mailer, mail_method, delivery_method, *args, **kwargs)
+      end
+    end
+  end
+end
+
+ActionMailer::MailDeliveryJob.prepend(OpenStreetMap::ActionMailer::MailDeliveryJob)