1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-01 03:57:15 +00:00

Fix sending mail with DeliveryJob is deprecated (#29914, #32908).

Patch by Pavel Rosický.


git-svn-id: http://svn.redmine.org/redmine/trunk@20882 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2021-04-01 14:41:03 +00:00
parent 5d9458726f
commit ba6ace46d7
4 changed files with 10 additions and 8 deletions

View File

@ -642,13 +642,13 @@ class Mailer < ActionMailer::Base
# Rake will likely end, causing the in-process thread pool to be deleted, before
# any/all of the .deliver_later emails are processed
def self.with_synched_deliveries(&block)
adapter = ActionMailer::DeliveryJob.queue_adapter
adapter = ActionMailer::MailDeliveryJob.queue_adapter
if adapter.is_a?(ActiveJob::QueueAdapters::AsyncAdapter)
ActionMailer::DeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
end
yield
ensure
ActionMailer::DeliveryJob.queue_adapter = adapter
ActionMailer::MailDeliveryJob.queue_adapter = adapter
end
def mail(headers={}, &block)

View File

@ -33,6 +33,8 @@ module RedmineApp
config.active_record.store_full_sti_class = true
config.active_record.default_timezone = :local
config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'

View File

@ -16,7 +16,7 @@ module Redmine
["Rails version", Rails::VERSION::STRING],
["Environment", Rails.env],
["Database adapter", ActiveRecord::Base.connection.adapter_name],
["Mailer queue", ActionMailer::DeliveryJob.queue_adapter.class.name],
["Mailer queue", ActionMailer::MailDeliveryJob.queue_adapter.class.name],
["Mailer delivery", ActionMailer::Base.delivery_method]
].map {|info| " %-30s %s" % info}.join("\n") + "\n"

View File

@ -1064,14 +1064,14 @@ class MailerTest < ActiveSupport::TestCase
end
def test_with_synched_deliveries_should_yield_with_synced_deliveries
ActionMailer::DeliveryJob.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new
ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new
Mailer.with_synched_deliveries do
assert_kind_of ActiveJob::QueueAdapters::InlineAdapter, ActionMailer::DeliveryJob.queue_adapter
assert_kind_of ActiveJob::QueueAdapters::InlineAdapter, ActionMailer::MailDeliveryJob.queue_adapter
end
assert_kind_of ActiveJob::QueueAdapters::AsyncAdapter, ActionMailer::DeliveryJob.queue_adapter
assert_kind_of ActiveJob::QueueAdapters::AsyncAdapter, ActionMailer::MailDeliveryJob.queue_adapter
ensure
ActionMailer::DeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
end
def test_email_addresses_should_keep_addresses