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
@@ -154,6 +154,36 @@ func (repository deliveryRepository) ListAttempts(ctx context.Context, id uuid.U
|
||||
return attempts, nil
|
||||
}
|
||||
|
||||
func (repository deliveryRepository) LatestForRecipient(ctx context.Context, recipientUserID uuid.UUID, kind domain.MailKind) (outbound.DeliveryStatusSnapshot, error) {
|
||||
const location = "deliveryRepository.LatestForRecipient"
|
||||
row, err := repository.queries.GetLatestDeliveryStatus(ctx, sqlc.GetLatestDeliveryStatusParams{
|
||||
RecipientUserID: pgUUID(recipientUserID),
|
||||
Kind: string(kind),
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return outbound.DeliveryStatusSnapshot{}, fmt.Errorf("%s - select delivery status: %w", location, outbound.ErrDeliveryNotFound)
|
||||
}
|
||||
if err != nil {
|
||||
return outbound.DeliveryStatusSnapshot{}, fmt.Errorf("%s - select delivery status: %w", location, mapDeliveryError(err))
|
||||
}
|
||||
storedKind, err := domain.ParseMailKind(row.Kind)
|
||||
if err != nil {
|
||||
return outbound.DeliveryStatusSnapshot{}, fmt.Errorf("%s - decode kind: %w", location, err)
|
||||
}
|
||||
status, err := domain.ParseDeliveryStatus(row.Status)
|
||||
if err != nil {
|
||||
return outbound.DeliveryStatusSnapshot{}, fmt.Errorf("%s - decode status: %w", location, err)
|
||||
}
|
||||
return outbound.DeliveryStatusSnapshot{
|
||||
DeliveryID: uuid.UUID(row.ID.Bytes),
|
||||
Kind: storedKind,
|
||||
Status: status,
|
||||
NextAttemptAt: zeroableTime(row.NextAttemptAt),
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (repository deliveryRepository) RecordAttempt(ctx context.Context, next domain.Delivery, attempt domain.DeliveryAttempt) error {
|
||||
const location = "deliveryRepository.RecordAttempt"
|
||||
if next.IsZero() || attempt.DeliveryID != next.ID() || attempt.Number != next.AttemptCount() || next.Version() <= 1 {
|
||||
|
||||
Reference in new issue
Block a user