scheduler

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package scheduler provides cron-based scheduling for automated email sync.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateCronExpr

func ValidateCronExpr(expr string) error

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 New

func New(syncFunc SyncFunc) *Scheduler

New creates a new Scheduler with the given sync callback.

func (*Scheduler) AddAccount

func (s *Scheduler) AddAccount(email, cronExpr string) error

AddAccount schedules sync for an account using the given cron expression. Returns an error if the cron expression is invalid.

func (*Scheduler) AddAccountsFromConfig

func (s *Scheduler) AddAccountsFromConfig(cfg *config.Config) (int, []error)

AddAccountsFromConfig adds all enabled accounts from the config. Returns the number of accounts scheduled and any errors encountered.

func (*Scheduler) IsRunning

func (s *Scheduler) IsRunning() bool

IsRunning returns true if the scheduler has been started and not yet stopped.

func (*Scheduler) IsScheduled

func (s *Scheduler) IsScheduled(email string) bool

IsScheduled returns true if the account has been added to the scheduler.

func (*Scheduler) RemoveAccount

func (s *Scheduler) RemoveAccount(email string)

RemoveAccount removes the schedule for an account.

func (*Scheduler) Start

func (s *Scheduler) Start()

Start begins executing scheduled jobs.

func (*Scheduler) Status

func (s *Scheduler) Status() []AccountStatus

Status returns the current status of all scheduled accounts.

func (*Scheduler) Stop

func (s *Scheduler) Stop() context.Context

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

func (s *Scheduler) TriggerSync(email string) error

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.

func (*Scheduler) WithLogger

func (s *Scheduler) WithLogger(logger *slog.Logger) *Scheduler

WithLogger sets the logger for the scheduler.

type SyncFunc

type SyncFunc func(ctx context.Context, email string) error

SyncFunc is the callback invoked when a scheduled sync should run. It receives the account email and should perform incremental sync + cache build.

Jump to

Keyboard shortcuts

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