core

package
v2.0.21 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCatchUpTimes

func GetCatchUpTimes(t *models.Trigger, to time.Time) ([]time.Time, error)

GetCatchUpTimes returns all scheduled times in (lastExecTime, to] for a trigger.

func ListActiveScheduleTriggers

func ListActiveScheduleTriggers(ctx context.Context, repo interfaces.TriggerRepo) ([]*models.Trigger, error)

ListActiveScheduleTriggers returns all non-deleted, active triggers with automation_type = TYPE_SCHEDULE.

func ParseSchedule

func ParseSchedule(t *models.Trigger) (cron.Schedule, error)

ParseSchedule returns a cron.Schedule for the trigger's automation spec. Supports both cron expressions and fixed-rate schedules. Returns (nil, nil) if the trigger has no schedule automation.

func StartTime

func StartTime(t *models.Trigger) (time.Time, error)

StartTime returns the earliest point from which to start scheduling. For fixed-rate schedules with a start_time, returns that start_time advanced past the last execution time. Otherwise falls back to TriggeredAt or DeployedAt.

func TriggerKey

func TriggerKey(t *models.Trigger) string

TriggerKey returns a stable string key for this job (used as the cron job name).

Types

type Executor

type Executor interface {
	Execute(ctx context.Context, t *models.Trigger, scheduledAt time.Time) error
}

Executor fires a single scheduled run.

type GoCronJob

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

GoCronJob wraps a *models.Trigger and fires the executor at each scheduled time. It implements cron.TimedJob so the scheduler passes the exact scheduled time to Run.

func NewGoCronJob

func NewGoCronJob(ctx context.Context, t *models.Trigger, executor Executor) *GoCronJob

NewGoCronJob constructs a GoCronJob.

func (*GoCronJob) Run

func (j *GoCronJob) Run(scheduledAt time.Time)

Run is called by the cron scheduler with the exact scheduled trigger time.

type GoCronScheduler

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

GoCronScheduler manages a set of cron jobs, one per active trigger. It is safe for concurrent use.

func NewGoCronScheduler

func NewGoCronScheduler(executor Executor) *GoCronScheduler

NewGoCronScheduler constructs a GoCronScheduler.

func (*GoCronScheduler) CatchupAll

func (s *GoCronScheduler) CatchupAll(
	ctx context.Context,
	triggers []*models.Trigger,
	now time.Time,
	maxRunsPerLoop int,
)

CatchupAll fires catchup runs for all triggers that have missed scheduled times. It processes at most maxRunsPerLoop total runs across all triggers.

func (*GoCronScheduler) Start

func (s *GoCronScheduler) Start()

Start starts the underlying cron scheduler. It is non-blocking.

func (*GoCronScheduler) Stop

func (s *GoCronScheduler) Stop() context.Context

Stop gracefully stops the cron scheduler, waiting for running jobs to finish.

func (*GoCronScheduler) UpdateSchedules

func (s *GoCronScheduler) UpdateSchedules(ctx context.Context, triggers []*models.Trigger)

UpdateSchedules reconciles the set of running cron jobs with the supplied active triggers. New triggers are added; triggers no longer present are removed; triggers whose spec changed are replaced.

type ScheduleSyncer

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

ScheduleSyncer periodically reloads active schedule triggers from the database and reconciles the running cron jobs via GoCronScheduler.

func NewScheduleSyncer

func NewScheduleSyncer(
	triggerRepo interfaces.TriggerRepo,
	scheduler *GoCronScheduler,
	resyncInterval time.Duration,
) *ScheduleSyncer

NewScheduleSyncer constructs a ScheduleSyncer.

func (*ScheduleSyncer) Run

func (s *ScheduleSyncer) Run(ctx context.Context) error

Run starts the sync loop. It blocks until ctx is cancelled.

Jump to

Keyboard shortcuts

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