package inbound import ( "context" "github.com/google/uuid" "lincodex/backend/internal/domain" ) // MailPassOutcome is what one pass of the sending worker did. The values // are closed and safe to log and to use as a label. type MailPassOutcome string const ( // MailPassIdle: no delivery was due. MailPassIdle MailPassOutcome = "idle" // MailPassAccepted: the provider accepted the message. It is not // delivery to a person. MailPassAccepted MailPassOutcome = "accepted" // MailPassRejected: the provider refused the message for good. MailPassRejected MailPassOutcome = "rejected" // MailPassRetry: the provider refused for now; the delivery is pending // again at its scheduled time. MailPassRetry MailPassOutcome = "retry" // MailPassWaitingQuota: the local or the provider quota is used up; the // delivery waits for the reset. MailPassWaitingQuota MailPassOutcome = "waiting_quota" // MailPassUnknown: the attempt may have reached the provider without a // conclusive answer, or an earlier attempt that lost its worker is in // doubt beyond the provider's idempotency window. MailPassUnknown MailPassOutcome = "unknown" // MailPassCancelled: the message must not be sent, and the delivery // ended with a reason. MailPassCancelled MailPassOutcome = "cancelled" // MailPassChannelUnavailable: no transport is active // (EMAIL_PROVIDER=disabled). Nothing was sent, and the delivery is left // as it was. MailPassChannelUnavailable MailPassOutcome = "channel_unavailable" // MailPassInterrupted: the context ended before the request was sent. // Nothing was sent, and the delivery is left as it was. MailPassInterrupted MailPassOutcome = "interrupted" // MailPassRowFailed: the worker itself failed on a delivery (not a // provider answer); it is due again later and counted, and is cancelled // as processing_failed after repeated failures. MailPassRowFailed MailPassOutcome = "row_failed" // MailPassLeaseLost: another worker recorded the result of this delivery // first; nothing of this attempt is kept. MailPassLeaseLost MailPassOutcome = "lease_lost" ) // MailPassResult is the outcome of one pass. It carries identifiers and // closed values only, never the address or the content. type MailPassResult struct { Outcome MailPassOutcome DeliveryID uuid.UUID Kind domain.MailKind // CancelReason is set for MailPassCancelled. CancelReason domain.DeliveryCancelReason } // MailPass runs one pass of the sending worker: it takes the next due // delivery through the claim, the single transport call, and the stored // result. type MailPass interface { // ProcessNext claims no new work once ctx ends; workCtx bounds the // transport call and should outlive ctx by a shutdown grace. An error // reports a database failure, after which the delivery stays under its // lease until it expires. ProcessNext(ctx, workCtx context.Context) (MailPassResult, error) // PauseFailureCounting tells the pass not to count failures of single rows // (a failing row is still moved back, but not counted and never // cancelled). The worker pauses it when failures hit one row after another, // which points at a global fault, and resumes it when a pass succeeds. PauseFailureCounting(paused bool) }