types

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CronTrigger

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

CronTrigger fires on a robfig/cron v3 6-field cron schedule (seconds minute hour dom month dow), e.g. "0 30 9 * * 1-5" for weekdays at 09:30:00.

robfig/cron v3 defaults to 5-field (no seconds); WithSeconds() is used to enable the 6-field format with seconds as the first field.

NOTE: This trigger is used by the internal system job scheduler. User-defined task schedules use 5-field cron expressions without seconds, parsed via cron.ParseStandard() in the task schedule dispatcher.

func NewCronTrigger

func NewCronTrigger(expr string) (*CronTrigger, error)

NewCronTrigger creates a Trigger that fires on a cron schedule. expr must be a robfig/cron v3 6-field expression, e.g. "0 0 2 * * *" for daily at 02:00:00. Returns an error if the expression is invalid.

func (*CronTrigger) Description

func (t *CronTrigger) Description() string

Description returns "cron(<expr>)", e.g. "cron(0 0 2 * * *)".

func (*CronTrigger) Emit

func (t *CronTrigger) Emit(ctx context.Context, ch chan<- Event)

Emit starts the cron scheduler and sends an empty Event on ch at each scheduled time until ctx is cancelled. If the relay has not consumed the previous event when the next tick fires, that tick is dropped (the send into ch is non-blocking with a ctx.Done guard).

type Event

type Event struct {
	Type    EventType
	Payload any
}

Event carries a type and an arbitrary payload.

type EventTrigger

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

EventTrigger forwards events from an external channel. It is the bridge between an event source (e.g. a poller that detects leaks) and the scheduler pipeline. The caller owns the source channel and controls its lifetime; closing it exhausts the trigger.

func NewEventTrigger

func NewEventTrigger(ch <-chan Event) *EventTrigger

NewEventTrigger creates a Trigger that fires whenever an event arrives on ch. Emit returns when ch is closed or ctx is cancelled.

func (*EventTrigger) Description

func (t *EventTrigger) Description() string

Description returns "event".

func (*EventTrigger) Emit

func (t *EventTrigger) Emit(ctx context.Context, ch chan<- Event)

Emit forwards each Event received from the source channel into ch until the source channel is closed or ctx is cancelled. Each forwarded send is guarded by ctx.Done so that a cancellation arriving while the relay has not yet consumed the previous event does not leak this goroutine.

type EventType

type EventType string

EventType identifies the kind of event.

const (
	EventLeakDetected EventType = "leak.detected"
)

type IntervalTrigger

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

IntervalTrigger fires on a fixed time interval.

func NewIntervalTrigger

func NewIntervalTrigger(interval time.Duration) (*IntervalTrigger, error)

NewIntervalTrigger creates a Trigger that fires on a fixed time interval. Returns an error if interval is non-positive; time.NewTicker would panic with the same input.

func (*IntervalTrigger) Description

func (t *IntervalTrigger) Description() string

Description returns "interval(<duration>)", e.g. "interval(30s)".

func (*IntervalTrigger) Emit

func (t *IntervalTrigger) Emit(ctx context.Context, ch chan<- Event)

Emit sends an empty Event on ch after each interval tick until ctx is cancelled. The send into ch is itself guarded by ctx so that a cancellation arriving while the relay has not yet consumed the previous event does not leak this goroutine.

type Job

type Job interface {
	Name() string
	Run(ctx context.Context, ev Event) error
}

Job is the unit of work executed by the scheduler.

type OnceTrigger

type OnceTrigger struct{}

OnceTrigger fires exactly once, immediately when Emit is called. It is useful for jobs that should run once at scheduler startup (e.g. an initial sync before the periodic interval takes over).

func NewOnceTrigger

func NewOnceTrigger() *OnceTrigger

NewOnceTrigger creates a Trigger that fires exactly once.

func (*OnceTrigger) Description

func (t *OnceTrigger) Description() string

Description returns "once".

func (*OnceTrigger) Emit

func (t *OnceTrigger) Emit(ctx context.Context, ch chan<- Event)

Emit sends a single empty Event on ch and returns. If ctx is cancelled before the relay consumes the event, Emit returns without sending.

type Policy

type Policy int

Policy controls what happens when a trigger fires while a job is running.

const (
	// Skip drops the new event if the worker is busy. Default.
	Skip Policy = iota
	// Queue keeps only the latest pending event; delivers it when the worker
	// is free. Earlier events are discarded.
	Queue
	// QueueAll buffers every event and delivers them in FIFO order.
	// Use this when each event carries unique data that must not be dropped.
	QueueAll
	// Replace cancels the current job and starts a new one.
	Replace
)

type Trigger

type Trigger interface {
	// Description returns a human-readable name for logging.
	Description() string

	// Emit writes events into ch until ctx is cancelled or the trigger
	// is exhausted. The scheduler closes ch after Emit returns.
	Emit(ctx context.Context, ch chan<- Event)
}

Trigger defines when events are emitted to the scheduler. Implementations are called in a dedicated goroutine by the scheduler.

Jump to

Keyboard shortcuts

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