cron

package
v0.0.0-...-eaf5e47 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CronJob

type CronJob struct {
	ID          uuid.UUID
	Name        string
	Type        string
	Payload     []byte
	Schedule    string
	MaxRetries  int
	LastFiredAt *time.Time
}

CronJob is the in-memory representation of a cron_jobs row.

type PGCronStore

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

PGCronStore implements cron.Store against PostgreSQL.

func NewPGCronStore

func NewPGCronStore(pool *pgxpool.Pool) *PGCronStore

func (*PGCronStore) ListEnabledCronJobs

func (s *PGCronStore) ListEnabledCronJobs(ctx context.Context) ([]*CronJob, error)

func (*PGCronStore) UpdateLastFired

func (s *PGCronStore) UpdateLastFired(ctx context.Context, id uuid.UUID, firedAt time.Time) error

func (*PGCronStore) UpsertCronJob

func (s *PGCronStore) UpsertCronJob(ctx context.Context, cj *CronJob) (*CronJob, error)

type Runner

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

Runner manages cron job definitions and spawns one-off job entries into the jobs table when a cron expression fires.

Design: cron entries create rows in the jobs table; the existing scheduler claims and executes them. This gives cron jobs retry semantics for free and makes them visible in ListJobs without any special-casing.

func NewRunner

func NewRunner(js store.Store, cs Store, log zerolog.Logger) *Runner

func (*Runner) LoadAndStart

func (r *Runner) LoadAndStart(ctx context.Context) error

LoadAndStart reads all enabled cron definitions from the DB, registers them with robfig/cron, then starts the internal ticker goroutine. Must be called once after migrations complete.

The provided ctx is used for all jobs spawned by this runner. When ctx is cancelled (e.g. on leadership loss), new job insertions are aborted rather than using context.Background(), which would keep writing to a DB that may no longer be owned by this node.

func (*Runner) Stop

func (r *Runner) Stop()

Stop gracefully waits for the currently running cron tick to finish.

type Store

type Store interface {
	ListEnabledCronJobs(ctx context.Context) ([]*CronJob, error)
	UpdateLastFired(ctx context.Context, id uuid.UUID, firedAt time.Time) error
	UpsertCronJob(ctx context.Context, cj *CronJob) (*CronJob, error)
}

Store is the persistence interface for cron job definitions.

Jump to

Keyboard shortcuts

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