package database // DeliveryStatus represents the status of a delivery type DeliveryStatus string // Delivery status values. const ( DeliveryStatusPending DeliveryStatus = "pending" DeliveryStatusDelivered DeliveryStatus = "delivered" DeliveryStatusFailed DeliveryStatus = "failed" DeliveryStatusRetrying DeliveryStatus = "retrying" ) // Terminal reports whether a delivery in this status has finished, so // the delivery engine will make no further attempt of its own. // // It is what decides which deliveries the event log offers to replay: // a pending or retrying delivery is still the engine's, and replaying // one would race it. func (s DeliveryStatus) Terminal() bool { switch s { case DeliveryStatusDelivered, DeliveryStatusFailed: return true case DeliveryStatusPending, DeliveryStatusRetrying: return false default: return false } } // Delivery represents a delivery attempt for an event to a target type Delivery struct { BaseModel EventID string `gorm:"type:uuid;not null" json:"eventId"` TargetID string `gorm:"type:uuid;not null" json:"targetId"` Status DeliveryStatus `gorm:"not null;default:'pending'" json:"status"` // Relations Event Event `json:"event,omitzero"` Target Target `json:"target,omitzero"` DeliveryResults []DeliveryResult `json:"deliveryResults,omitempty"` }