Documentation
¶
Overview ¶
Package notify - subscribable notification framework for the task engine.
The Producer turns the durable audit log into best-effort Redis pub/sub notifications: an interval timer periodically polls the audit table for events not yet broadcast, publishes each to its routed channels, then stamps them as broadcast. Production is at-least-once (the broadcast marker survives restarts and re-publishes the crash window); delivery is best-effort (Redis pub/sub drops messages for offline subscribers).
The Consumer is its subscriber counterpart: it subscribes to a set of topics (literal channels or glob patterns), deserializes each received payload into a models.NotificationEvent, and hands it to a caller-supplied callback. Subscribers inherit the two delivery contracts - duplicates happen (dedupe on event.ID) and offline subscribers miss events (catch up via the audit log). See notify/DESIGN.md.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
type Consumer interface {
/*
Start the notification consumer's subscription reader
@param ctx context.Context - execution context
*/
Start(ctx context.Context) error
/*
Stop the notification consumer's subscription reader
@param ctx context.Context - execution context
*/
Stop(ctx context.Context) error
}
Consumer notification consumer - the subscriber counterpart to Producer.
A Consumer subscribes to a set of notification topics (literal channels or glob patterns, e.g. notify:subject:task:*) and delivers each received notification, deserialized into a models.NotificationEvent, to a caller-supplied callback. It owns the PubSubMessage -> NotificationEvent conversion internally, so the caller never touches the raw pub/sub envelope.
Delivery inherits the framework's two contracts: duplicates happen (dedupe on event.ID) and delivery is best-effort (a Consumer offline at broadcast time simply misses the event; catch up by reading the audit log directly). See notify/DESIGN.md.
func NewConsumer ¶
func NewConsumer(parentCtx context.Context, params NewConsumerParams) (Consumer, error)
NewConsumer define a new notification consumer
@param parentCtx context.Context - the parent execution context @param params NewConsumerParams - parameters of the notification consumer @returns new notification consumer
type NewConsumerParams ¶
type NewConsumerParams struct {
// Redis REDIS client
Redis goutilsRedis.Client `validate:"required"`
// Topics the notification topics to subscribe on. Literal channels or glob patterns (the
// underlying subscriber uses PSUBSCRIBE), built via the models.BuildNotify*ChannelName helpers.
Topics []string `validate:"required,min=1,dive,required"`
// Callback invoked for each deserialized notification
Callback NotificationCallback `validate:"required"`
// Name subscriber name for the underlying goutils Subscriber (log/debug identity)
Name string `validate:"required"`
}
NewConsumerParams init parameters for a notification consumer
type NewProducerParams ¶
type NewProducerParams struct {
// Persistence persistence client
Persistence db.Client `validate:"required"`
// Config notification producer config
Config models.NotificationProducerConfig `validate:"required"`
// Redis REDIS client
Redis goutilsRedis.Client `validate:"required"`
}
NewProducerParams init parameters for a notification producer
type NotificationCallback ¶
type NotificationCallback func(ctx context.Context, event models.NotificationEvent)
NotificationCallback receives each deserialized notification.
ctx is the subscriber's working context - it is cancelled when the Consumer is stopped, so a long-running callback can observe it and bail out early. The callback is invoked serially (from the underlying subscriber's single reader goroutine) and MUST return promptly: a slow callback stalls consumption and can cause messages to be dropped. Offload heavy work (DB reconciliation, DAG advancement) onto the callback owner's own goroutine or queue.
type Producer ¶
type Producer interface {
/*
Start the notification producer's poll loop
@param ctx context.Context - execution context
*/
Start(ctx context.Context) error
/*
Stop the notification producer's poll loop
@param ctx context.Context - execution context
*/
Stop(ctx context.Context) error
}
Producer notification producer
func NewProducer ¶
func NewProducer(parentCtx context.Context, params NewProducerParams) (Producer, error)
NewProducer define a new notification producer
@param parentCtx context.Context - the parent execution context @param params NewProducerParams - parameters of the notification producer @returns new notification producer