feat(notification): add Resend quota gate and waiting-for-reset state
This commit is contained in:
1 parent
3b917befa9
commit
b856d4ff54
40 files changed
+4116
-48
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
@@ -98,9 +99,10 @@ type providerAnswer struct {
|
||||
// have been accepted. Repeating cannot succeed and a new key could send
|
||||
// the message twice: the delivery layer stops and escalates on this code.
|
||||
// - 409 without a known name: unknown, since it may be either of the above.
|
||||
// - 429 daily_quota_exceeded: quota_exhausted until the next midnight UTC;
|
||||
// 429 monthly_quota_exceeded: quota_exhausted without a wait hint, the
|
||||
// reset depends on the billing cycle; other 429: rate_limited with
|
||||
// - 429 daily_quota_exceeded: quota_exhausted with QuotaPeriod day until
|
||||
// the next midnight UTC; 429 monthly_quota_exceeded: quota_exhausted
|
||||
// with QuotaPeriod month and without a wait hint, the reset depends on
|
||||
// the billing cycle; other 429: rate_limited with
|
||||
// Retry-After or RateLimit-Reset.
|
||||
// - other 4xx (validation, key, permission, not found): invalid_request.
|
||||
// - 503 service_unavailable: rejected temporary; the API refused the
|
||||
@@ -155,9 +157,11 @@ func classifyTooManyRequests(name string, header http.Header, now time.Time) out
|
||||
switch name {
|
||||
case errorNameDailyQuota:
|
||||
// The daily quota resets at midnight UTC, not after a rolling day.
|
||||
return rejected(outbound.MailRejectionQuotaExhausted, untilNextUTCMidnight(now))
|
||||
return quotaExhausted(domain.MailQuotaPeriodDay, untilNextUTCMidnight(now))
|
||||
case errorNameMonthlyQuota:
|
||||
return rejected(outbound.MailRejectionQuotaExhausted, 0)
|
||||
// The monthly reset follows the account's billing cycle, which the
|
||||
// API does not report.
|
||||
return quotaExhausted(domain.MailQuotaPeriodMonth, 0)
|
||||
default:
|
||||
return rejected(outbound.MailRejectionRateLimited, rateLimitWait(header, now))
|
||||
}
|
||||
@@ -167,6 +171,12 @@ func rejected(reason outbound.MailRejection, wait time.Duration) outbound.SendRe
|
||||
return outbound.SendResult{Outcome: outbound.MailOutcomeRejected, Rejection: reason, RetryAfter: wait}
|
||||
}
|
||||
|
||||
func quotaExhausted(period domain.MailQuotaPeriod, wait time.Duration) outbound.SendResult {
|
||||
result := rejected(outbound.MailRejectionQuotaExhausted, wait)
|
||||
result.QuotaPeriod = period
|
||||
return result
|
||||
}
|
||||
|
||||
func unknownResult(wait time.Duration) outbound.SendResult {
|
||||
return outbound.SendResult{Outcome: outbound.MailOutcomeUnknown, RetryAfter: wait}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user