Aggiunge sulla dashboard invii il KPI mail/ora dagli invii SMTP confermati.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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
|
||||
Reference in New Issue
Block a user