Documentation
¶
Overview ¶
Package scheduler provides cron-based scheduling for automated email sync.
Index ¶
- func ValidateCronExpr(expr string) error
- type AccountStatus
- type Scheduler
- func (s *Scheduler) AddAccount(email, cronExpr string) error
- func (s *Scheduler) AddAccountsFromConfig(cfg *config.Config) (int, []error)
- func (s *Scheduler) IsRunning() bool
- func (s *Scheduler) IsScheduled(email string) bool
- func (s *Scheduler) RemoveAccount(email string)
- func (s *Scheduler) Start()
- func (s *Scheduler) Status() []AccountStatus
- func (s *Scheduler) Stop() context.Context
- func (s *Scheduler) TriggerSync(email string) error
- func (s *Scheduler) WithLogger(logger *slog.Logger) *Scheduler
- type SyncFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateCronExpr ¶
ValidateCronExpr validates a cron expression without scheduling anything.
Types ¶
type AccountStatus ¶
type AccountStatus struct {
Email string `json:"email"`
Running bool `json:"running"`
LastRun time.Time `json:"last_run,omitempty"`
NextRun time.Time `json:"next_run"`
Schedule string `json:"schedule"`
LastError string `json:"last_error,omitempty"`
}
AccountStatus represents the sync status of a scheduled account.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages cron-based email sync scheduling.
func (*Scheduler) AddAccount ¶
AddAccount schedules sync for an account using the given cron expression. Returns an error if the cron expression is invalid.
func (*Scheduler) AddAccountsFromConfig ¶
AddAccountsFromConfig adds all enabled accounts from the config. Returns the number of accounts scheduled and any errors encountered.
func (*Scheduler) IsRunning ¶
IsRunning returns true if the scheduler has been started and not yet stopped.
func (*Scheduler) IsScheduled ¶
IsScheduled returns true if the account has been added to the scheduler.
func (*Scheduler) RemoveAccount ¶
RemoveAccount removes the schedule for an account.
func (*Scheduler) Status ¶
func (s *Scheduler) Status() []AccountStatus
Status returns the current status of all scheduled accounts.
func (*Scheduler) Stop ¶
Stop gracefully stops the scheduler, cancels running sync jobs, and waits for them to finish. Returns a context that is done when all work completes.
func (*Scheduler) TriggerSync ¶
TriggerSync manually triggers a sync for an account (outside of schedule). Returns an error if a sync is already running, the account is not scheduled, or the scheduler has been stopped.