scheduler

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

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 New

New ensures the schedule-enabled stream exists and returns a Scheduler.

func (*Scheduler) After

func (s *Scheduler) After(ctx context.Context, key string, d time.Duration, payload []byte) error

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) At

func (s *Scheduler) At(ctx context.Context, key string, when time.Time, payload []byte) error

At schedules a one-shot delivery of payload to FireSubject(key) at when.

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

func (s *Scheduler) Cron(ctx context.Context, name, key, expr string, payload []byte) error

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

func (s *Scheduler) FireSubject(key string) string

FireSubject returns the fire subject for a logical key (e.g. an execution id).

Jump to

Keyboard shortcuts

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