Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Job
- type JobPayload
- type JobStatus
- type JobType
- type Scheduler
- func (s *Scheduler) GetJob(identifier any) (*Job, error)
- func (s *Scheduler) ListJobs() ([]Job, error)
- func (s *Scheduler) Reschedule(identifier any, newSpec string, newMetadata map[string]any) (*Job, error)
- func (s *Scheduler) RunNow(identifier any) error
- func (s *Scheduler) Schedule(name, spec string, function any, metadata map[string]any) (*Job, error)
- func (s *Scheduler) Stop()
- func (s *Scheduler) Unschedule(identifier any) error
- type Storage
- type WebUI
Constants ¶
View Source
const ( DefaultMaxConcurrentJobs = 10 DefaultJobTimeout = 30 * time.Second DefaultWebListen = "localhost:8080" )
Default configuration values
Variables ¶
View Source
var ( ErrJobNameEmpty = errors.New("job name cannot be empty") ErrJobFunctionNil = errors.New("job function cannot be nil") ErrJobFunctionInvalid = errors.New("job function must be a valid function") ErrJobFunctionNameEmpty = errors.New("could not determine function name") ErrJobNotFound = errors.New("job not found") ErrFunctionNotFound = errors.New("function not registered") ErrJobTimeout = errors.New("job execution timed out") ErrJobAlreadyRunning = errors.New("job is already running") ErrConcurrencyLimit = errors.New("concurrency limit reached") )
Error definitions for the job scheduler
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
MaxConcurrentJobs int // Maximum number of concurrent jobs
JobTimeout time.Duration // Timeout duration for job execution
EnableWebUI bool // Whether to enable web interface
WebListen string // Web interface listen address
}
Config holds the configuration for the job scheduler
func DefaultConfig ¶ added in v0.0.2
func DefaultConfig() Config
DefaultConfig returns the default configuration
type Job ¶ added in v0.0.2
type Job struct {
gorm.Model
JobID uuid.UUID `gorm:"type:uuid;primaryKey"`
Name string `gorm:"not null;size:255"`
Spec string `gorm:"not null;size:100"`
Payload JobPayload `gorm:"type:jsonb"`
Status JobStatus `gorm:"index;size:20;default:scheduled"`
LastRun *time.Time `gorm:"index"`
NextRun time.Time `gorm:"index"`
RunCount int `gorm:"default:0"`
SuccessCount int `gorm:"default:0"`
FailCount int `gorm:"default:0"`
LastError string `gorm:"type:text"`
Latency int64 `gorm:"default:0"` // milliseconds
}
Job represents a scheduled job
type JobPayload ¶ added in v0.0.2
type JobPayload struct {
Type JobType `json:"type"`
Name string `json:"name"`
Func string `json:"func,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
JobPayload contains the execution details of a job
func (*JobPayload) Scan ¶ added in v0.0.2
func (jp *JobPayload) Scan(value any) error
Scan implements the Scanner interface for JobPayload
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages job scheduling and execution
func (*Scheduler) Reschedule ¶
func (s *Scheduler) Reschedule(identifier any, newSpec string, newMetadata map[string]any) (*Job, error)
Reschedule updates an existing job
func (*Scheduler) Schedule ¶
func (s *Scheduler) Schedule(name, spec string, function any, metadata map[string]any) (*Job, error)
Schedule creates and schedules a new job
func (*Scheduler) Unschedule ¶
Unschedule removes a job
type Storage ¶ added in v0.0.2
type Storage interface {
CreateJob(ctx context.Context, job *Job) error
UpdateJob(ctx context.Context, job *Job) error
DeleteJob(ctx context.Context, uuid uuid.UUID) error
GetJobByJobID(ctx context.Context, uuid uuid.UUID) (*Job, error)
GetJobByName(ctx context.Context, name string) (*Job, error)
ListJobs(ctx context.Context) ([]Job, error)
}
Storage defines the interface for job persistence
Source Files
¶
Click to show internal directories.
Click to hide internal directories.