Files
eminuxCRM/app/services/mailings/hourly_throughput.rb
T
eminuxandCursor 390cb0e657
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / scan_ruby (push) Has been cancelled
Aggiunge sulla dashboard invii il KPI mail/ora dagli invii SMTP confermati.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-07 12:43:39 +02:00

36 lines
622 B
Ruby

class Mailings::HourlyThroughput
HOUR = 1.hour
RECENT = 15.minutes
def initialize(project, now: Time.current)
@project = project
@now = now
end
def sent
@sent ||= sent_since(HOUR)
end
def recent_sent
@recent_sent ||= sent_since(RECENT)
end
def failed
@failed ||= recipients.failed.where(updated_at: (@now - HOUR)..@now).count
end
def drained
sent + failed
end
private
def sent_since(window)
recipients.sent.where(sent_at: (@now - window)..@now).count
end
def recipients
MailingRecipient.joins(:mailing).merge(Mailing.for_project(@project))
end
end