mirror of
https://github.com/mastodon/mastodon.git
synced 2025-07-15 16:58:14 +00:00
Change terms of service e-mail job to be iterable (#35126)
This commit is contained in:
parent
e60014ed9c
commit
1be48d0cab
|
@ -1,15 +1,18 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Admin::DistributeAnnouncementNotificationWorker
|
class Admin::DistributeAnnouncementNotificationWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::IterableJob
|
||||||
|
include BulkMailer
|
||||||
|
|
||||||
def perform(announcement_id)
|
def build_enumerator(announcement_id, cursor:)
|
||||||
announcement = Announcement.find(announcement_id)
|
@announcement = Announcement.find(announcement_id)
|
||||||
|
|
||||||
announcement.scope_for_notification.find_each do |user|
|
active_record_batches_enumerator(@announcement.scope_for_notification, cursor:)
|
||||||
UserMailer.announcement_published(user, announcement).deliver_later!
|
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
true
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def each_iteration(batch_of_users, _announcement_id)
|
||||||
|
push_bulk_mailer(UserMailer, :announcement_published, batch_of_users.map { |user| [user, @announcement] })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Admin::DistributeTermsOfServiceNotificationWorker
|
class Admin::DistributeTermsOfServiceNotificationWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::IterableJob
|
||||||
|
include BulkMailer
|
||||||
|
|
||||||
def perform(terms_of_service_id)
|
def build_enumerator(terms_of_service_id, cursor:)
|
||||||
terms_of_service = TermsOfService.find(terms_of_service_id)
|
@terms_of_service = TermsOfService.find(terms_of_service_id)
|
||||||
|
|
||||||
terms_of_service.scope_for_interstitial.in_batches.update_all(require_tos_interstitial: true)
|
active_record_batches_enumerator(@terms_of_service.scope_for_notification, cursor:)
|
||||||
|
|
||||||
terms_of_service.scope_for_notification.find_each do |user|
|
|
||||||
UserMailer.terms_of_service_changed(user, terms_of_service).deliver_later!
|
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
true
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def each_iteration(batch_of_users, _terms_of_service_id)
|
||||||
|
push_bulk_mailer(UserMailer, :terms_of_service_changed, batch_of_users.map { |user| [user, @terms_of_service] })
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_start
|
||||||
|
@terms_of_service.scope_for_interstitial.in_batches.update_all(require_tos_interstitial: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
25
app/workers/concerns/bulk_mailer.rb
Normal file
25
app/workers/concerns/bulk_mailer.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module BulkMailer
|
||||||
|
def push_bulk_mailer(mailer_class, mailer_method, args_array)
|
||||||
|
raise ArgumentError, "No method #{mailer_method} on class #{mailer_class.name}" unless mailer_class.respond_to?(mailer_method)
|
||||||
|
|
||||||
|
job_class = ActionMailer::MailDeliveryJob
|
||||||
|
|
||||||
|
Sidekiq::Client.push_bulk({
|
||||||
|
'class' => ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper,
|
||||||
|
'wrapped' => job_class,
|
||||||
|
'queue' => mailer_class.deliver_later_queue_name,
|
||||||
|
'args' => args_array.map do |args|
|
||||||
|
[
|
||||||
|
job_class.new(
|
||||||
|
mailer_class.name,
|
||||||
|
mailer_method.to_s,
|
||||||
|
'deliver_now',
|
||||||
|
args: args
|
||||||
|
).serialize,
|
||||||
|
]
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user