notification

package
v0.0.1-beta.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cooldown

type Cooldown struct {
	// contains filtered or unexported fields
}

Cooldown provides atomic per-channel threshold cooldown via Redis. Key = c3api:notification:balance-warning:email:<userID>:<thresholdMillis> Value = random token, NX EX 86400. Only the token owner may delete.

func NewCooldown

func NewCooldown(client *redis.Client) *Cooldown

NewCooldown constructs a cooldown helper. client must be non-nil (Redis is a required dependency; nil panics to surface wiring errors early).

func (*Cooldown) Clear

func (c *Cooldown) Clear(ctx context.Context, userID, thresholdMillis int64) error

Clear deletes a known retired threshold claim regardless of token ownership. Preference updates intentionally retire the entire old warning cycle.

func (*Cooldown) Release

func (c *Cooldown) Release(ctx context.Context, event domain.BalanceWarningEvent, token string) error

Release atomically deletes the key only if the stored value equals token. Uses Lua compare-delete to avoid GET->DEL race.

func (*Cooldown) TryClaim

func (c *Cooldown) TryClaim(ctx context.Context, event domain.BalanceWarningEvent) (string, bool, error)

TryClaim attempts to atomically claim the cooldown slot. It returns (token, true, nil) on success (caller owns the claim), (\"\", false, nil) when another claimant holds it, or an error on Redis failure.

type WarningMailEnqueue

type WarningMailEnqueue func(domain.BalanceWarningEvent, func(error)) error

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

func New

func New(cooldown *Cooldown, enabled func() bool, enqueue WarningMailEnqueue, log *logx.Logger) *Worker

func (*Worker) Close

func (w *Worker) Close(ctx context.Context) (err error)

func (*Worker) Name

func (w *Worker) Name() string

func (*Worker) Start

func (w *Worker) Start(ctx context.Context) error

func (*Worker) Stats

func (w *Worker) Stats() any

func (*Worker) TrySubmit

func (w *Worker) TrySubmit(event domain.BalanceWarningEvent) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL