Adds logic to send proposal notifications in batches
WIP batches tests
This commit is contained in:
@@ -24,6 +24,19 @@ class Admin::SystemEmailsController < Admin::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def moderate_pending
|
||||
ProposalNotification.find(params[:id]).moderate_system_email(current_user)
|
||||
|
||||
redirect_to admin_system_email_preview_pending_path("proposal_notification_digest")
|
||||
end
|
||||
|
||||
def send_pending
|
||||
Notification.send_pending
|
||||
|
||||
flash[:notice] = t("admin.system_emails.preview_pending.send_pending_notification")
|
||||
redirect_to admin_system_emails_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_system_email
|
||||
|
||||
@@ -68,4 +68,29 @@ class Notification < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def self.send_pending
|
||||
run_at = first_batch_run_at
|
||||
User.email_digest.find_in_batches(batch_size: batch_size) do |users|
|
||||
users.each do |user|
|
||||
email_digest = EmailDigest.new(user)
|
||||
email_digest.deliver(run_at)
|
||||
end
|
||||
run_at += batch_interval
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.batch_size
|
||||
10000
|
||||
end
|
||||
|
||||
def self.batch_interval
|
||||
20.minutes
|
||||
end
|
||||
|
||||
def self.first_batch_run_at
|
||||
Time.current
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user