Aggiunge pulsante per fermare un invio email in corso.
CI / scan_ruby (push) Failing after 14m2s
CI / scan_js (push) Successful in 12m13s
CI / lint (push) Failing after 11m23s

Permette di annullare i destinatari ancora in coda mantenendo le email già inviate.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 00:49:57 +02:00
co-authored by Cursor
parent 765ee51eeb
commit d98c3e87a8
7 changed files with 70 additions and 1 deletions
+15
View File
@@ -72,6 +72,10 @@ class Mailing < ApplicationRecord
status == "sent"
end
def cancelled?
status == "cancelled"
end
def editable?
draft?
end
@@ -187,6 +191,17 @@ class Mailing < ApplicationRecord
update!(status: "sent", completed_at: Time.current, next_send_at: nil)
end
def cancel_send!
raise "Solo un invio in corso può essere fermato" unless sending?
transaction do
mailing_recipients.where(status: %w[pending queued]).find_each do |recipient|
recipient.update!(status: "skipped", skip_reason: "invio annullato")
end
update!(status: "cancelled", next_send_at: nil, completed_at: Time.current)
end
end
private
def send_window_order
+7
View File
@@ -47,10 +47,13 @@ class MailingRecipient < ApplicationRecord
def deliver!
with_lock do
return if status.in?(%w[sent skipped])
return abort_delivery!("invio annullato") unless mailing.sending?
update!(status: "queued")
end
return unless mailing.sending?
html = rendered_html
subject_line = rendered_subject_line
CampaignMailer.outreach(self, html: html, subject: subject_line).deliver_now
@@ -63,6 +66,10 @@ class MailingRecipient < ApplicationRecord
private
def abort_delivery!(reason)
update!(status: "skipped", skip_reason: reason)
end
def record_success!(subject_line)
transaction do
update!(status: "sent", sent_at: Time.current, rendered_subject: subject_line, error_message: nil)