Documentation
¶
Overview ¶
Package order holds the queue handlers of billing's order tasks: the activation of paid orders, the deferred close of unpaid ones, the paid and pending order reconcilers, the order-event outbox publication and retention, and the daily order report. The handlers decode their payloads and call the billing facade, which owns every transaction.
Index ¶
- Constants
- type ActivateOrderHandler
- type CleanupOrderEventsHandler
- type DailyOrderReportHandler
- type DeferCloseOrderHandler
- type Dependencies
- type PaidOrderActivator
- type ProcessedMarkerPruner
- type PublishOrderEventsHandler
- type PublishedEventPruner
- type ReconcilePaidOrdersHandler
- type ReconcilePendingOrdersHandler
Constants ¶
const ( OrderTypeSubscribe = orderEntity.TypeSubscribe OrderTypeRenewal = orderEntity.TypeRenewal OrderTypeResetTraffic = orderEntity.TypeResetTraffic OrderTypeRecharge = orderEntity.TypeRecharge OrderStatusPending = orderEntity.StatusPending OrderStatusPaid = orderEntity.StatusPaid OrderStatusClose = orderEntity.StatusClosed OrderStatusFailed = orderEntity.StatusFailed OrderStatusFinished = orderEntity.StatusFinished )
Order types and statuses of the billing order entity, under the names the task adapters have always used.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivateOrderHandler ¶ added in v1.21.0
type ActivateOrderHandler struct {
// contains filtered or unexported fields
}
ActivateOrderHandler activates the paid order a task names. A failure goes back to asynq for a retry; the paid-order reconciler re-enqueues any order still paid after the retries.
func NewActivateOrderHandler ¶ added in v1.21.0
func NewActivateOrderHandler(activator PaidOrderActivator) *ActivateOrderHandler
NewActivateOrderHandler builds the handler over the billing facade.
func (*ActivateOrderHandler) ProcessTask ¶ added in v1.21.0
type CleanupOrderEventsHandler ¶ added in v1.21.0
type CleanupOrderEventsHandler struct {
// contains filtered or unexported fields
}
CleanupOrderEventsHandler applies the replay contract to billing's order events and to the platform kernel's published domain events and inbox markers. Billing removes only the order events that have already reached Redis and are older than the contract: unpublished events are never deleted, even if an outage lasts longer than the normal retention period.
func NewCleanupOrderEventsHandler ¶ added in v1.21.0
func NewCleanupOrderEventsHandler(deps Dependencies) *CleanupOrderEventsHandler
NewCleanupOrderEventsHandler builds the cleanup over the billing facade and the platform kernel's outbox and inbox.
func (*CleanupOrderEventsHandler) ProcessTask ¶ added in v1.21.0
ProcessTask runs the cleanups in turn under one cutoff and returns the first failure for asynq to retry the task; repeating the cleanups that already ran is harmless.
type DailyOrderReportHandler ¶ added in v1.21.0
type DailyOrderReportHandler struct {
// contains filtered or unexported fields
}
DailyOrderReportHandler posts the previous day's settlement summary into the admin group's notification topic. It reports yesterday because it runs after midnight, when the day it summarises is complete.
func NewDailyOrderReportHandler ¶ added in v1.21.0
func NewDailyOrderReportHandler(deps Dependencies) *DailyOrderReportHandler
NewDailyOrderReportHandler builds the report over the billing and notification facades.
func (*DailyOrderReportHandler) ProcessTask ¶ added in v1.21.0
type DeferCloseOrderHandler ¶ added in v1.21.0
type DeferCloseOrderHandler struct {
// contains filtered or unexported fields
}
DeferCloseOrderHandler closes a pending order once its payment window has passed. A failed close is retried for the first three attempts only; the pending-order reconciler closes whatever is left afterwards.
func NewDeferCloseOrderHandler ¶ added in v1.21.0
func NewDeferCloseOrderHandler(deps Dependencies) *DeferCloseOrderHandler
NewDeferCloseOrderHandler builds the handler over the billing facade.
func (*DeferCloseOrderHandler) ProcessTask ¶ added in v1.21.0
type Dependencies ¶
type Dependencies struct {
Queue *taskqueue.Client
Inspector *asynq.Inspector
Billing billing.Service
Notification notification.Service
Telegram func() config.Telegram
// Outbox and Inbox are the platform kernel's domain-event outbox and
// idempotent inbox, which the order-event cleanup prunes under the same
// replay contract as billing's order events.
Outbox PublishedEventPruner
Inbox ProcessedMarkerPruner
}
Dependencies are what the order task handlers are built from. Billing's tables are reached only through the billing facade; each handler narrows the facade to the methods it calls.
type PaidOrderActivator ¶
PaidOrderActivator is billing's activation of a paid order, identified by its order number. Each stage of the activation records its completion, so a retried or replayed task skips the stages that already committed.
type ProcessedMarkerPruner ¶ added in v1.21.0
type ProcessedMarkerPruner interface {
DeleteProcessedBefore(ctx context.Context, cutoff time.Time) (int64, error)
}
ProcessedMarkerPruner deletes the inbox markers of the steps processed before cutoff; the platform kernel's inbox provides it.
type PublishOrderEventsHandler ¶ added in v1.21.0
type PublishOrderEventsHandler struct {
// contains filtered or unexported fields
}
PublishOrderEventsHandler is the queue shell of billing's order-event outbox: the billing module drains the durable events onto the channels that wake the order event streams (ADR-001), and the scheduler's next tick drains whatever a run left behind.
func NewPublishOrderEventsHandler ¶ added in v1.21.0
func NewPublishOrderEventsHandler(deps Dependencies) *PublishOrderEventsHandler
NewPublishOrderEventsHandler builds the shell over the billing facade.
func (*PublishOrderEventsHandler) ProcessTask ¶ added in v1.21.0
ProcessTask runs one publication and hands its failure to asynq.
type PublishedEventPruner ¶ added in v1.21.0
type PublishedEventPruner interface {
DeletePublishedBefore(ctx context.Context, cutoff time.Time) (int64, error)
}
PublishedEventPruner deletes the domain events the event bus published before cutoff; the platform kernel's outbox provides it.
type ReconcilePaidOrdersHandler ¶ added in v1.21.0
type ReconcilePaidOrdersHandler struct {
// contains filtered or unexported fields
}
ReconcilePaidOrdersHandler treats the durable Paid state as an activation outbox. It repairs the database/Redis gap if a callback committed payment but Redis was unavailable before the activation task could be inserted.
func NewReconcilePaidOrdersHandler ¶ added in v1.21.0
func NewReconcilePaidOrdersHandler(deps Dependencies) *ReconcilePaidOrdersHandler
NewReconcilePaidOrdersHandler builds the reconciler over billing's order scan and the activation queue it repairs.
func (*ReconcilePaidOrdersHandler) ProcessTask ¶ added in v1.21.0
type ReconcilePendingOrdersHandler ¶ added in v1.21.0
type ReconcilePendingOrdersHandler struct {
// contains filtered or unexported fields
}
ReconcilePendingOrdersHandler is a durable fallback for deferred close tasks. State transitions in CloseOrder remain conditional, so a late callback can safely race this scan without turning a paid order back into a close order.
func NewReconcilePendingOrdersHandler ¶ added in v1.21.0
func NewReconcilePendingOrdersHandler(deps Dependencies) *ReconcilePendingOrdersHandler
NewReconcilePendingOrdersHandler builds the reconciler over the billing facade.