Documentation
¶
Index ¶
- Constants
- func NewModule() modular.Module
- type Job
- type JobExecution
- type JobFunc
- type JobStatus
- type JobStore
- type MemoryJobStore
- func (s *MemoryJobStore) AddJob(job Job) error
- func (s *MemoryJobStore) AddJobExecution(execution JobExecution) error
- func (s *MemoryJobStore) CleanupOldExecutions(before time.Time) error
- func (s *MemoryJobStore) DeleteJob(jobID string) error
- func (s *MemoryJobStore) GetDueJobs(before time.Time) ([]Job, error)
- func (s *MemoryJobStore) GetJob(jobID string) (Job, error)
- func (s *MemoryJobStore) GetJobExecutions(jobID string) ([]JobExecution, error)
- func (s *MemoryJobStore) GetJobs() ([]Job, error)
- func (s *MemoryJobStore) GetPendingJobs() ([]Job, error)
- func (s *MemoryJobStore) LoadFromFile(filePath string) ([]Job, error)
- func (s *MemoryJobStore) SaveToFile(jobs []Job, filePath string) error
- func (s *MemoryJobStore) UpdateJob(job Job) error
- func (s *MemoryJobStore) UpdateJobExecution(execution JobExecution) error
- type PersistableJobStore
- type Scheduler
- func (s *Scheduler) CancelJob(jobID string) error
- func (s *Scheduler) GetJob(jobID string) (Job, error)
- func (s *Scheduler) GetJobHistory(jobID string) ([]JobExecution, error)
- func (s *Scheduler) ListJobs() ([]Job, error)
- func (s *Scheduler) ResumeJob(job Job) (string, error)
- func (s *Scheduler) ResumeRecurringJob(job Job) (string, error)
- func (s *Scheduler) ScheduleJob(job Job) (string, error)
- func (s *Scheduler) ScheduleRecurring(name string, cronExpr string, jobFunc JobFunc) (string, error)
- func (s *Scheduler) Start(ctx context.Context) error
- func (s *Scheduler) Stop(ctx context.Context) error
- type SchedulerConfig
- type SchedulerModule
- func (m *SchedulerModule) CancelJob(jobID string) error
- func (m *SchedulerModule) Constructor() modular.ModuleConstructor
- func (m *SchedulerModule) Dependencies() []string
- func (m *SchedulerModule) GetJob(jobID string) (Job, error)
- func (m *SchedulerModule) GetJobHistory(jobID string) ([]JobExecution, error)
- func (m *SchedulerModule) Init(app modular.Application) error
- func (m *SchedulerModule) ListJobs() ([]Job, error)
- func (m *SchedulerModule) Name() string
- func (m *SchedulerModule) ProvidesServices() []modular.ServiceProvider
- func (m *SchedulerModule) RegisterConfig(app modular.Application) error
- func (m *SchedulerModule) RequiresServices() []modular.ServiceDependency
- func (m *SchedulerModule) ScheduleJob(job Job) (string, error)
- func (m *SchedulerModule) ScheduleRecurring(name string, cronExpr string, jobFunc JobFunc) (string, error)
- func (m *SchedulerModule) Start(ctx context.Context) error
- func (m *SchedulerModule) Stop(ctx context.Context) error
- type SchedulerOption
Constants ¶
const ModuleName = "scheduler"
ModuleName is the name of this module
const ServiceName = "scheduler.provider"
ServiceName is the name of the service provided by this module
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Job ¶
type Job struct {
ID string `json:"id"`
Name string `json:"name"`
Schedule string `json:"schedule,omitempty"`
RunAt time.Time `json:"runAt,omitempty"`
IsRecurring bool `json:"isRecurring"`
JobFunc JobFunc `json:"-"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Status JobStatus `json:"status"`
LastRun *time.Time `json:"lastRun,omitempty"`
NextRun *time.Time `json:"nextRun,omitempty"`
}
Job represents a scheduled job
type JobExecution ¶
type JobExecution struct {
JobID string `json:"jobId"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime,omitempty"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
}
JobExecution records details about a single execution of a job
type JobStatus ¶
type JobStatus string
JobStatus represents the status of a job
const ( // JobStatusPending indicates a job is waiting to be executed JobStatusPending JobStatus = "pending" // JobStatusRunning indicates a job is currently executing JobStatusRunning JobStatus = "running" // JobStatusCompleted indicates a job has completed successfully JobStatusCompleted JobStatus = "completed" // JobStatusFailed indicates a job has failed JobStatusFailed JobStatus = "failed" // JobStatusCancelled indicates a job has been cancelled JobStatusCancelled JobStatus = "cancelled" )
type JobStore ¶
type JobStore interface {
// AddJob stores a new job
AddJob(job Job) error
// UpdateJob updates an existing job
UpdateJob(job Job) error
// GetJob retrieves a job by ID
GetJob(jobID string) (Job, error)
// GetJobs returns all jobs
GetJobs() ([]Job, error)
// GetPendingJobs returns all pending jobs
GetPendingJobs() ([]Job, error)
// GetDueJobs returns jobs that are due to run at or before the given time
GetDueJobs(before time.Time) ([]Job, error)
// DeleteJob removes a job
DeleteJob(jobID string) error
// AddJobExecution records a job execution
AddJobExecution(execution JobExecution) error
// UpdateJobExecution updates a job execution
UpdateJobExecution(execution JobExecution) error
// GetJobExecutions retrieves execution history for a job
GetJobExecutions(jobID string) ([]JobExecution, error)
// CleanupOldExecutions removes execution records older than retention period
CleanupOldExecutions(before time.Time) error
}
JobStore defines the interface for job storage implementations
type MemoryJobStore ¶
type MemoryJobStore struct {
// contains filtered or unexported fields
}
MemoryJobStore implements JobStore using in-memory storage
func NewMemoryJobStore ¶
func NewMemoryJobStore(retentionPeriod time.Duration) *MemoryJobStore
NewMemoryJobStore creates a new memory job store
func (*MemoryJobStore) AddJob ¶
func (s *MemoryJobStore) AddJob(job Job) error
AddJob stores a new job
func (*MemoryJobStore) AddJobExecution ¶
func (s *MemoryJobStore) AddJobExecution(execution JobExecution) error
AddJobExecution records a job execution
func (*MemoryJobStore) CleanupOldExecutions ¶
func (s *MemoryJobStore) CleanupOldExecutions(before time.Time) error
CleanupOldExecutions removes execution records older than retention period
func (*MemoryJobStore) DeleteJob ¶
func (s *MemoryJobStore) DeleteJob(jobID string) error
DeleteJob removes a job
func (*MemoryJobStore) GetDueJobs ¶
func (s *MemoryJobStore) GetDueJobs(before time.Time) ([]Job, error)
GetDueJobs returns jobs that are due to run at or before the given time
func (*MemoryJobStore) GetJob ¶
func (s *MemoryJobStore) GetJob(jobID string) (Job, error)
GetJob retrieves a job by ID
func (*MemoryJobStore) GetJobExecutions ¶
func (s *MemoryJobStore) GetJobExecutions(jobID string) ([]JobExecution, error)
GetJobExecutions retrieves execution history for a job
func (*MemoryJobStore) GetJobs ¶
func (s *MemoryJobStore) GetJobs() ([]Job, error)
GetJobs returns all jobs
func (*MemoryJobStore) GetPendingJobs ¶
func (s *MemoryJobStore) GetPendingJobs() ([]Job, error)
GetPendingJobs returns all pending jobs
func (*MemoryJobStore) LoadFromFile ¶
func (s *MemoryJobStore) LoadFromFile(filePath string) ([]Job, error)
LoadFromFile loads jobs from a JSON file
func (*MemoryJobStore) SaveToFile ¶
func (s *MemoryJobStore) SaveToFile(jobs []Job, filePath string) error
SaveToFile saves jobs to a JSON file
func (*MemoryJobStore) UpdateJob ¶
func (s *MemoryJobStore) UpdateJob(job Job) error
UpdateJob updates an existing job
func (*MemoryJobStore) UpdateJobExecution ¶
func (s *MemoryJobStore) UpdateJobExecution(execution JobExecution) error
UpdateJobExecution updates a job execution
type PersistableJobStore ¶
type PersistableJobStore interface {
JobStore
// LoadFromFile loads jobs from a file
LoadFromFile(filePath string) ([]Job, error)
// SaveToFile saves jobs to a file
SaveToFile(jobs []Job, filePath string) error
}
PersistableJobStore extends JobStore with persistence capabilities
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler handles scheduling and executing jobs
func NewScheduler ¶
func NewScheduler(jobStore JobStore, opts ...SchedulerOption) *Scheduler
NewScheduler creates a new scheduler
func (*Scheduler) GetJobHistory ¶
func (s *Scheduler) GetJobHistory(jobID string) ([]JobExecution, error)
GetJobHistory returns the execution history for a job
func (*Scheduler) ResumeRecurringJob ¶
ResumeRecurringJob resumes a persisted recurring job, registering it with the cron scheduler
func (*Scheduler) ScheduleJob ¶
ScheduleJob schedules a new job
func (*Scheduler) ScheduleRecurring ¶
func (s *Scheduler) ScheduleRecurring(name string, cronExpr string, jobFunc JobFunc) (string, error)
ScheduleRecurring schedules a recurring job using a cron expression
type SchedulerConfig ¶
type SchedulerConfig struct {
// WorkerCount is the number of worker goroutines to run
WorkerCount int `json:"workerCount" yaml:"workerCount" validate:"min=1"`
// QueueSize is the maximum number of jobs to queue
QueueSize int `json:"queueSize" yaml:"queueSize" validate:"min=1"`
// ShutdownTimeout is the time in seconds to wait for graceful shutdown
ShutdownTimeout int `json:"shutdownTimeout" yaml:"shutdownTimeout" validate:"min=1"`
// StorageType is the type of job storage to use (memory, file, etc.)
StorageType string `json:"storageType" yaml:"storageType" validate:"oneof=memory file"`
// CheckInterval is how often to check for scheduled jobs (in seconds)
CheckInterval int `json:"checkInterval" yaml:"checkInterval" validate:"min=1"`
// RetentionDays is how many days to retain job history
RetentionDays int `json:"retentionDays" yaml:"retentionDays" validate:"min=1"`
// PersistenceFile is the file path for job persistence
PersistenceFile string `json:"persistenceFile" yaml:"persistenceFile"`
// EnablePersistence determines if jobs should be persisted between restarts
EnablePersistence bool `json:"enablePersistence" yaml:"enablePersistence"`
}
SchedulerConfig defines the configuration for the scheduler module
type SchedulerModule ¶
type SchedulerModule struct {
// contains filtered or unexported fields
}
SchedulerModule represents the scheduler module
func (*SchedulerModule) CancelJob ¶
func (m *SchedulerModule) CancelJob(jobID string) error
CancelJob cancels a scheduled job
func (*SchedulerModule) Constructor ¶
func (m *SchedulerModule) Constructor() modular.ModuleConstructor
Constructor provides a dependency injection constructor for the module
func (*SchedulerModule) Dependencies ¶
func (m *SchedulerModule) Dependencies() []string
Dependencies returns the names of modules this module depends on
func (*SchedulerModule) GetJob ¶
func (m *SchedulerModule) GetJob(jobID string) (Job, error)
GetJob returns information about a scheduled job
func (*SchedulerModule) GetJobHistory ¶
func (m *SchedulerModule) GetJobHistory(jobID string) ([]JobExecution, error)
GetJobHistory returns the execution history for a job
func (*SchedulerModule) Init ¶
func (m *SchedulerModule) Init(app modular.Application) error
Init initializes the module
func (*SchedulerModule) ListJobs ¶
func (m *SchedulerModule) ListJobs() ([]Job, error)
ListJobs returns a list of all scheduled jobs
func (*SchedulerModule) Name ¶
func (m *SchedulerModule) Name() string
Name returns the name of the module
func (*SchedulerModule) ProvidesServices ¶
func (m *SchedulerModule) ProvidesServices() []modular.ServiceProvider
ProvidesServices declares services provided by this module
func (*SchedulerModule) RegisterConfig ¶
func (m *SchedulerModule) RegisterConfig(app modular.Application) error
RegisterConfig registers the module's configuration structure
func (*SchedulerModule) RequiresServices ¶
func (m *SchedulerModule) RequiresServices() []modular.ServiceDependency
RequiresServices declares services required by this module
func (*SchedulerModule) ScheduleJob ¶
func (m *SchedulerModule) ScheduleJob(job Job) (string, error)
ScheduleJob schedules a new job
func (*SchedulerModule) ScheduleRecurring ¶
func (m *SchedulerModule) ScheduleRecurring(name string, cronExpr string, jobFunc JobFunc) (string, error)
ScheduleRecurring schedules a recurring job using a cron expression
type SchedulerOption ¶
type SchedulerOption func(*Scheduler)
SchedulerOption defines a function that can configure a scheduler
func WithCheckInterval ¶
func WithCheckInterval(interval time.Duration) SchedulerOption
WithCheckInterval sets how often to check for scheduled jobs
func WithQueueSize ¶
func WithQueueSize(size int) SchedulerOption
WithQueueSize sets the job queue size
func WithWorkerCount ¶
func WithWorkerCount(count int) SchedulerOption
WithWorkerCount sets the number of workers