cron

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cron provides management of cron drop-in files and periodic scripts. Supports /etc/cron.d/ (custom schedules) and /etc/cron.{hourly,daily,weekly,monthly}/ (interval-based scripts). Delegates file writes to the file provider for SHA tracking, idempotency, and template rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateResult

type CreateResult struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

CreateResult represents the outcome of a cron entry creation.

type Darwin

type Darwin struct{}

Darwin implements the Provider interface for Darwin (macOS). All methods return ErrUnsupported as cron.d is not available on macOS.

func NewDarwinProvider

func NewDarwinProvider() *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) Create

func (d *Darwin) Create(
	_ context.Context,
	_ Entry,
) (*CreateResult, error)

Create returns ErrUnsupported on Darwin.

func (*Darwin) Delete

func (d *Darwin) Delete(
	_ context.Context,
	_ string,
) (*DeleteResult, error)

Delete returns ErrUnsupported on Darwin.

func (*Darwin) Get

func (d *Darwin) Get(
	_ context.Context,
	_ string,
) (*Entry, error)

Get returns ErrUnsupported on Darwin.

func (*Darwin) List

func (d *Darwin) List(
	_ context.Context,
) ([]Entry, error)

List returns ErrUnsupported on Darwin.

func (*Darwin) Update

func (d *Darwin) Update(
	_ context.Context,
	_ Entry,
) (*UpdateResult, error)

Update returns ErrUnsupported on Darwin.

type Debian

type Debian struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Debian implements the Provider interface for Debian-family systems. It delegates file writes to a FileDeployer for SHA tracking and idempotency. Managed files are identified by their presence in the file-state KV, not by file content headers.

func NewDebianProvider

func NewDebianProvider(
	logger *slog.Logger,
	fs avfs.VFS,
	fileDeployer file.Deployer,
	stateKV jetstream.KeyValue,
	hostname string,
) *Debian

NewDebianProvider factory to create a new Debian instance.

func (*Debian) Create

func (d *Debian) Create(
	ctx context.Context,
	entry Entry,
) (*CreateResult, error)

Create deploys a new cron entry via the file provider.

func (*Debian) Delete

func (d *Debian) Delete(
	ctx context.Context,
	name string,
) (*DeleteResult, error)

Delete undeploys a cron entry via the file provider.

func (*Debian) Get

func (d *Debian) Get(
	ctx context.Context,
	name string,
) (*Entry, error)

Get returns a single cron entry by name, searching all directories.

func (*Debian) List

func (d *Debian) List(
	ctx context.Context,
) ([]Entry, error)

List returns all osapi-managed cron entries from /etc/cron.d/ and /etc/cron.{hourly,daily,weekly,monthly}/.

func (*Debian) Update

func (d *Debian) Update(
	ctx context.Context,
	entry Entry,
) (*UpdateResult, error)

Update redeploys an existing cron entry via the file provider.

type DeleteResult

type DeleteResult struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

DeleteResult represents the outcome of a cron entry deletion.

type Entry

type Entry struct {
	Name        string         `json:"name"`
	Object      string         `json:"object,omitempty"`
	Schedule    string         `json:"schedule,omitempty"`
	Interval    string         `json:"interval,omitempty"`
	Source      string         `json:"source,omitempty"`
	User        string         `json:"user,omitempty"`
	ContentType string         `json:"content_type,omitempty"`
	Vars        map[string]any `json:"vars,omitempty"`
}

Entry represents a cron entry — either a /etc/cron.d/ drop-in file with a custom schedule or a /etc/cron.{interval}/ periodic script.

type Linux

type Linux struct{}

Linux implements the Provider interface for generic Linux. All methods return ErrUnsupported; use the Debian provider for Debian-family systems.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) Create

func (l *Linux) Create(
	_ context.Context,
	_ Entry,
) (*CreateResult, error)

Create returns ErrUnsupported on generic Linux.

func (*Linux) Delete

func (l *Linux) Delete(
	_ context.Context,
	_ string,
) (*DeleteResult, error)

Delete returns ErrUnsupported on generic Linux.

func (*Linux) Get

func (l *Linux) Get(
	_ context.Context,
	_ string,
) (*Entry, error)

Get returns ErrUnsupported on generic Linux.

func (*Linux) List

func (l *Linux) List(
	_ context.Context,
) ([]Entry, error)

List returns ErrUnsupported on generic Linux.

func (*Linux) Update

func (l *Linux) Update(
	_ context.Context,
	_ Entry,
) (*UpdateResult, error)

Update returns ErrUnsupported on generic Linux.

type Provider

type Provider interface {
	// List returns all osapi-managed cron entries.
	List(ctx context.Context) ([]Entry, error)
	// Get returns a single cron entry by name.
	Get(ctx context.Context, name string) (*Entry, error)
	// Create deploys a new cron entry via the file provider.
	Create(ctx context.Context, entry Entry) (*CreateResult, error)
	// Update redeploys an existing cron entry via the file provider.
	Update(ctx context.Context, entry Entry) (*UpdateResult, error)
	// Delete undeploys a cron entry via the file provider.
	Delete(ctx context.Context, name string) (*DeleteResult, error)
}

Provider implements the methods to manage cron entries.

type UpdateResult

type UpdateResult struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

UpdateResult represents the outcome of a cron entry update.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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