cron

package
v0.66.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cron implements one-shot execution of project-defined scheduled tasks declared in devx.yaml's `cron:` block. The schedule expression is informational in this version — `devx cron run <name>` fires the job immediately with the same env + secrets a `devx shell` session would get, so developers can verify the job's behavior without waiting for the production cron schedule to roll around.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTimeout

func ParseTimeout(s string) (time.Duration, error)

ParseTimeout converts the YAML-string timeout to a duration. An empty string yields zero (meaning no timeout). Surfaced separately so the CLI layer can validate timeouts at load time rather than at execute time.

func SortedNames

func SortedNames(jobs []Job) []string

SortedNames returns job names in alphabetical order — used by `devx cron list` for stable output and by error messages that hint at valid names.

Types

type ExecuteConfig

type ExecuteConfig struct {
	Job     Job
	Secrets map[string]string // merged with Job.Env (Job.Env wins on conflict)
	WorkDir string            // working directory for the subprocess; "" means inherit
	// Stdout / Stderr default to os.Stdout / os.Stderr when nil. Injectable
	// for tests so we can assert on captured output.
	Stdout *os.File
	Stderr *os.File
}

ExecuteConfig holds the runtime parameters for a single Execute call.

type Job

type Job struct {
	Name        string
	Schedule    string
	Command     []string
	Description string
	Timeout     time.Duration
	Env         map[string]string
}

Job is the in-memory shape of a single cron entry, normalized from the devx.yaml DevxConfigCron struct. The cmd package converts to this so the cron package has no dependency on cmd.

func FindByName

func FindByName(jobs []Job, name string) (Job, bool)

FindByName performs a case-sensitive lookup in the job list. Returns (Job, true) on hit, (zero, false) on miss.

func (Job) Validate

func (j Job) Validate() error

Validate checks the invariants required to actually execute a job. Returns nil if the job is runnable.

type Result

type Result struct {
	Job        string        `json:"job"`
	StartedAt  time.Time     `json:"started_at"`
	Duration   time.Duration `json:"duration"`
	DurationMs int64         `json:"duration_ms"`
	ExitCode   int           `json:"exit_code"`
	TimedOut   bool          `json:"timed_out,omitempty"`
	Error      string        `json:"error,omitempty"`
}

Result captures the outcome of a single run for both human and JSON reporting. ExitCode is -1 if the process failed to start.

func Execute

func Execute(ctx context.Context, cfg ExecuteConfig) (Result, error)

Execute runs the job once with the merged env, streaming stdout/stderr to the configured writers. Honors the job's Timeout if set; honors ctx cancellation always. Returns a populated Result even on error so callers can render it uniformly.

Jump to

Keyboard shortcuts

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