Documentation
¶
Overview ¶
Package cron provides cron job scheduling using the robfig/cron library
Package cron provides service integration for cron scheduling
Index ¶
- type CleanupServiceInterface
- type Config
- type InstrumentedScheduler
- func (is *InstrumentedScheduler) AddJob(cronExpr string, jobName string, job func()) error
- func (is *InstrumentedScheduler) AddJobWithError(cronExpr string, jobName string, job func() error) error
- func (is *InstrumentedScheduler) AddPasswordResetCleanupJob(cronExpr string, cleanupService CleanupServiceInterface) error
- func (is *InstrumentedScheduler) AddPasswordResetCleanupJobWithService(cronExpr string, cleanupService *reset.CleanupService) error
- func (is *InstrumentedScheduler) GetActiveJobCount() int64
- func (is *InstrumentedScheduler) GetEntries() []cron.Entry
- func (is *InstrumentedScheduler) GetSystemHealthCallbacks() (getActiveJobCount func() int64, getTotalJobCount func() int64)
- func (is *InstrumentedScheduler) GetSystemStatus() int64
- func (is *InstrumentedScheduler) GetTotalJobCount() int64
- func (is *InstrumentedScheduler) Start()
- func (is *InstrumentedScheduler) Stop()
- type JobInfo
- type Scheduler
- func (s *Scheduler) AddJob(cronExpr string, jobName string, job func()) error
- func (s *Scheduler) AddPasswordResetCleanupJob(cronExpr string, cleanupService CleanupServiceInterface) error
- func (s *Scheduler) AddPasswordResetCleanupJobWithService(cronExpr string, cleanupService *reset.CleanupService) error
- func (s *Scheduler) GetEntries() []cron.Entry
- func (s *Scheduler) Start()
- func (s *Scheduler) Stop()
- type Service
- func (s *Service) AddCustomJob(cronExpr string, jobName string, job func()) error
- func (s *Service) GetJobEntries() []JobInfo
- func (s *Service) IsEnabled() bool
- func (s *Service) RunPasswordResetCleanupOnce(ctx context.Context, queries models.Querier) error
- func (s *Service) SetupPasswordResetCleanup(queries models.Querier, config ServiceConfig) error
- func (s *Service) Start() error
- func (s *Service) Stop()
- type ServiceConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CleanupServiceInterface ¶
CleanupServiceInterface defines the interface for cleanup services
type Config ¶
type Config struct { // PasswordResetCleanupCron is the cron expression for password reset token cleanup // Default: "*/5 * * * *" (every 5 minutes) PasswordResetCleanupCron string // TimeZone for cron jobs (default: UTC) TimeZone string }
Config holds configuration for the cron scheduler
type InstrumentedScheduler ¶ added in v0.4.0
type InstrumentedScheduler struct {
// contains filtered or unexported fields
}
InstrumentedScheduler wraps the cron scheduler with metrics collection
func NewInstrumentedScheduler ¶ added in v0.4.0
func NewInstrumentedScheduler(config Config, logger *slog.Logger, systemMetrics *metrics.SystemHealthMetrics) (*InstrumentedScheduler, error)
NewInstrumentedScheduler creates a new instrumented cron scheduler
func (*InstrumentedScheduler) AddJob ¶ added in v0.4.0
func (is *InstrumentedScheduler) AddJob(cronExpr string, jobName string, job func()) error
AddJob adds an instrumented generic cron job
func (*InstrumentedScheduler) AddJobWithError ¶ added in v0.4.0
func (is *InstrumentedScheduler) AddJobWithError(cronExpr string, jobName string, job func() error) error
AddJobWithError adds an instrumented cron job that can return an error
func (*InstrumentedScheduler) AddPasswordResetCleanupJob ¶ added in v0.4.0
func (is *InstrumentedScheduler) AddPasswordResetCleanupJob(cronExpr string, cleanupService CleanupServiceInterface) error
AddPasswordResetCleanupJob adds an instrumented password reset cleanup job
func (*InstrumentedScheduler) AddPasswordResetCleanupJobWithService ¶ added in v0.4.0
func (is *InstrumentedScheduler) AddPasswordResetCleanupJobWithService(cronExpr string, cleanupService *reset.CleanupService) error
AddPasswordResetCleanupJobWithService adds an instrumented password reset cleanup job with *reset.CleanupService
func (*InstrumentedScheduler) GetActiveJobCount ¶ added in v0.4.0
func (is *InstrumentedScheduler) GetActiveJobCount() int64
GetActiveJobCount returns the current number of running cron jobs
func (*InstrumentedScheduler) GetEntries ¶ added in v0.4.0
func (is *InstrumentedScheduler) GetEntries() []cron.Entry
GetEntries returns information about scheduled jobs
func (*InstrumentedScheduler) GetSystemHealthCallbacks ¶ added in v0.4.0
func (is *InstrumentedScheduler) GetSystemHealthCallbacks() ( getActiveJobCount func() int64, getTotalJobCount func() int64, )
GetSystemHealthCallbacks returns callback functions for system health metrics
func (*InstrumentedScheduler) GetSystemStatus ¶ added in v0.4.0
func (is *InstrumentedScheduler) GetSystemStatus() int64
GetSystemStatus returns the overall cron system health status Returns 1 if healthy, 0 if unhealthy
func (*InstrumentedScheduler) GetTotalJobCount ¶ added in v0.4.0
func (is *InstrumentedScheduler) GetTotalJobCount() int64
GetTotalJobCount returns the total number of scheduled cron jobs
func (*InstrumentedScheduler) Start ¶ added in v0.4.0
func (is *InstrumentedScheduler) Start()
Start starts the instrumented cron scheduler
func (*InstrumentedScheduler) Stop ¶ added in v0.4.0
func (is *InstrumentedScheduler) Stop()
Stop stops the instrumented cron scheduler
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages cron jobs using the robfig/cron library
func NewScheduler ¶
NewScheduler creates a new cron scheduler
func (*Scheduler) AddPasswordResetCleanupJob ¶
func (s *Scheduler) AddPasswordResetCleanupJob(cronExpr string, cleanupService CleanupServiceInterface) error
AddPasswordResetCleanupJob adds a job to clean up expired password reset tokens
func (*Scheduler) AddPasswordResetCleanupJobWithService ¶
func (s *Scheduler) AddPasswordResetCleanupJobWithService(cronExpr string, cleanupService *reset.CleanupService) error
AddPasswordResetCleanupJobWithService is a convenience method that accepts *reset.CleanupService directly
func (*Scheduler) GetEntries ¶
func (s *Scheduler) GetEntries() []cron.Entry
GetEntries returns information about scheduled jobs
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages cron jobs for the application
func NewService ¶
func NewService(config ServiceConfig, logger *slog.Logger) (*Service, error)
NewService creates a new cron service
func (*Service) AddCustomJob ¶
AddCustomJob adds a custom cron job
func (*Service) GetJobEntries ¶
GetJobEntries returns information about scheduled jobs
func (*Service) RunPasswordResetCleanupOnce ¶
RunPasswordResetCleanupOnce runs the password reset cleanup job once (useful for testing)
func (*Service) SetupPasswordResetCleanup ¶
func (s *Service) SetupPasswordResetCleanup(queries models.Querier, config ServiceConfig) error
SetupPasswordResetCleanup configures password reset token cleanup job
type ServiceConfig ¶
type ServiceConfig struct { // PasswordResetCleanupCron is the cron expression for password reset token cleanup // Default: "*/5 * * * *" (every 5 minutes) PasswordResetCleanupCron string // TimeZone for cron jobs (default: UTC) TimeZone string // Enabled determines if cron jobs should run Enabled bool }
ServiceConfig holds configuration for the cron service
func LoadServiceConfigFromViper ¶
func LoadServiceConfigFromViper() ServiceConfig
LoadServiceConfigFromViper loads cron service configuration from viper