Documentation
¶
Overview ¶
Package sweep implements the subscription lifecycle sweep: marking traffic-exceeded and expired subscriptions finished, then firing the retryable side effects (owner notification, cache invalidation). Only the module facade may reach it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deps ¶
type Deps struct {
UserSubs repository.UserSubscriptionRepo
Plans repository.SubscribeRepo
Cache repository.UserCacheRepo
Store repository.Store
Emails OwnerEmailReader
Notify Notifier
}
Deps declares the subdomain's dependencies; the module facade forwards them from the composition root.
type Notifier ¶
type Notifier interface {
NotifySubscriptionExpired(ctx context.Context, email string, expiredAt time.Time)
NotifyTrafficExceeded(ctx context.Context, email string)
// NotifySubscriptionExpiring warns the owner before the subscription
// stops. Renewal amount is in minor units; an empty plan name or a zero
// amount means the plan could not be read.
NotifySubscriptionExpiring(ctx context.Context, userID int64, planName string, expireAt time.Time, renewalAmount int64)
}
Notifier delivers the lifecycle notices to the subscription owner. The composition root adapts it to the notification queue until a notification facade owns email delivery.
type OwnerEmailReader ¶
type OwnerEmailReader interface {
FindUserAuthMethodsByUserIds(ctx context.Context, method string, userIds []int64) ([]*user.AuthMethods, error)
}
OwnerEmailReader is the read-only identity port resolving a user's email binding; the legacy user-auth repository satisfies it structurally.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the lifecycle-sweep entry point used by the subscription facade.
func NewService ¶
func (*Service) CheckSubscriptions ¶
CheckSubscriptions runs both lifecycle sweeps. Each sweep commits its status flip in a subscription-domain transaction; notifications and cache invalidation are retryable side effects that run after the commit (ADR-001 step 2).
func (*Service) RemindExpiringSubscribes ¶ added in v1.15.16
RemindExpiringSubscribes announces subscriptions about to expire. A subscription that cannot be announced is skipped rather than failing the pass: nothing here changes subscription state, and the next daily run retries it while the expiry stays inside the window.