Documentation
¶
Overview ¶
Package scheduler wraps the NATS JetStream Message Scheduler. The engine never runs its own timers: every programmed pause (retry backoff, signal/wait timeout, recurring flow start) is published as a scheduled message and the NATS server delivers it, at the right time, to a "fire" subject that the engine consumes.
The server requires a schedule's target subject to be captured by the same schedule-enabled stream, so fired messages land on packtrail.sched.fire.<key> and a durable consumer (ConsumeFired) forwards them onward.
Index ¶
- type Scheduler
- func (s *Scheduler) After(ctx context.Context, key string, d time.Duration, payload []byte) error
- func (s *Scheduler) At(ctx context.Context, key string, when time.Time, payload []byte) error
- func (s *Scheduler) ConsumeFired(ctx context.Context, durable string, ...) (jetstream.ConsumeContext, error)
- func (s *Scheduler) Cron(ctx context.Context, name, key, expr string, payload []byte) error
- func (s *Scheduler) FireSubject(key string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler publishes scheduled messages to a schedule-enabled stream.
func (*Scheduler) After ¶
After schedules a one-shot delivery of payload to FireSubject(key) after d. Each call creates an independent schedule, so concurrent timers for the same key never overwrite one another.
func (*Scheduler) ConsumeFired ¶
func (s *Scheduler) ConsumeFired( ctx context.Context, durable string, handler func(key string, payload []byte) error, ) (jetstream.ConsumeContext, error)
ConsumeFired sets up a durable consumer that invokes handler for every fired schedule. handler receives the fire subject's key and the original payload. The returned ConsumeContext must be stopped by the caller.
func (*Scheduler) Cron ¶
Cron installs (or replaces) a recurring schedule named name that delivers payload to FireSubject(key) on the given 6-field cron expression ("sec min hour dom mon dow"). Reusing name replaces the schedule.
func (*Scheduler) FireSubject ¶
FireSubject returns the fire subject for a logical key (e.g. an execution id).