core

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package core contains shared interfaces to avoid import cycles.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrJobNotFound       = errors.New("job not found")
	ErrJobAlreadyExists  = errors.New("job already exists")
	ErrInvalidSchedule   = errors.New("invalid cron schedule")
	ErrHandlerNotFound   = errors.New("handler not found")
	ErrExecutionNotFound = errors.New("execution not found")
	ErrInvalidData       = errors.New("invalid data received from storage")
)

Standard errors for the cron extension

Functions

func ListSchedulers

func ListSchedulers() []string

ListSchedulers returns the names of all registered schedulers.

func ListStorages

func ListStorages() []string

ListStorages returns the names of all registered storage backends.

func RegisterSchedulerFactory

func RegisterSchedulerFactory(name string, factory SchedulerFactory)

RegisterSchedulerFactory registers a scheduler factory with a given name.

func RegisterStorageFactory

func RegisterStorageFactory(name string, factory StorageFactory)

RegisterStorageFactory registers a storage factory with a given name.

Types

type Scheduler

type Scheduler interface {
	// Lifecycle methods
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	IsRunning() bool
	IsLeader() bool // For distributed schedulers

	// Job management
	// Note: job parameter is *cron.Job, returns []*cron.Job
	AddJob(job interface{}) error
	RemoveJob(jobID string) error
	UpdateJob(job interface{}) error
	ListJobs() ([]interface{}, error)
	GetJob(jobID string) (interface{}, error)

	// Manual execution
	TriggerJob(ctx context.Context, jobID string) (string, error)
}

Scheduler defines the interface for job schedulers.

This interface is defined in the core package to avoid import cycles between the main cron package and scheduler implementations.

func CreateScheduler

func CreateScheduler(name string, config interface{}, deps *SchedulerDeps) (Scheduler, error)

CreateScheduler creates a scheduler instance using the registered factory.

type SchedulerDeps

type SchedulerDeps struct {
	Storage  interface{} // cron.Storage
	Executor interface{} // *cron.Executor
	Registry interface{} // *cron.JobRegistry
	Logger   interface{} // forge.Logger
}

SchedulerDeps holds dependencies needed to create a scheduler. The actual types (Storage, Executor, etc.) are from the parent cron package, but we use interface{} here to avoid import cycles.

type SchedulerFactory

type SchedulerFactory func(config interface{}, deps *SchedulerDeps) (Scheduler, error)

SchedulerFactory is a function that creates a Scheduler instance.

type Storage

type Storage interface {
	// Connection management
	Connect(ctx context.Context) error
	Disconnect(ctx context.Context) error
	Ping(ctx context.Context) error

	// Job CRUD operations
	// Note: job, update parameters are *cron.Job, *cron.JobUpdate
	// Returns are *cron.Job, []*cron.Job
	SaveJob(ctx context.Context, job interface{}) error
	GetJob(ctx context.Context, id string) (interface{}, error)
	ListJobs(ctx context.Context) ([]interface{}, error)
	UpdateJob(ctx context.Context, id string, update interface{}) error
	DeleteJob(ctx context.Context, id string) error

	// Execution history
	// Note: exec parameter is *cron.JobExecution, filter is *cron.ExecutionFilter
	// Returns are *cron.JobExecution, []*cron.JobExecution
	SaveExecution(ctx context.Context, exec interface{}) error
	GetExecution(ctx context.Context, id string) (interface{}, error)
	ListExecutions(ctx context.Context, filter interface{}) ([]interface{}, error)
	DeleteExecution(ctx context.Context, id string) error
	DeleteExecutionsBefore(ctx context.Context, before time.Time) (int64, error)
	DeleteExecutionsByJob(ctx context.Context, jobID string) (int64, error)

	// Statistics
	// Returns *cron.JobStats
	GetJobStats(ctx context.Context, jobID string) (interface{}, error)
	GetExecutionCount(ctx context.Context, filter interface{}) (int64, error)

	// Distributed locking (optional, only for Redis backend)
	AcquireLock(ctx context.Context, jobID string, ttl time.Duration) (bool, error)
	ReleaseLock(ctx context.Context, jobID string) error
	RefreshLock(ctx context.Context, jobID string, ttl time.Duration) error
}

Storage defines the interface for persisting jobs and executions. Implementations must be thread-safe.

This interface is defined in the core package to avoid import cycles between the main cron package and storage implementations. Storage implementations should import both core (for the interface) and cron (for the types).

func CreateStorage

func CreateStorage(name string, config interface{}) (Storage, error)

CreateStorage creates a storage instance using the registered factory.

type StorageFactory

type StorageFactory func(config interface{}) (Storage, error)

StorageFactory is a function that creates a Storage instance.

Jump to

Keyboard shortcuts

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