Documentation
¶
Overview ¶
Package jobscheduler provides a means to schedule work across multiple queues while limiting overall work.
Index ¶
- type Config
- type Provider
- type RootScheduler
- func (q *RootScheduler) Close() error
- func (q *RootScheduler) Submit(queue, id string, run func(ctx context.Context) error)
- func (q *RootScheduler) SubmitPeriodicJob(queue, id string, interval time.Duration, run func(ctx context.Context) error)
- func (q *RootScheduler) Wait()
- func (q *RootScheduler) WithQueuePrefix(prefix string) Scheduler
- type ScheduleStore
- type Scheduler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Concurrency int `hcl:"concurrency" help:"The maximum number of concurrent jobs to run (0 means number of cores)." default:"4"`
MaxCloneConcurrency int `` /* 173-byte string literal not displayed */
SchedulerDB string `hcl:"scheduler-db" help:"Path to the scheduler state database." default:"${CACHEW_STATE}/scheduler.db"`
}
type Provider ¶
type Provider func() (*RootScheduler, error)
type RootScheduler ¶
type RootScheduler struct {
// contains filtered or unexported fields
}
func New ¶
func New(ctx context.Context, config Config) (*RootScheduler, error)
New creates a new JobScheduler.
func (*RootScheduler) Close ¶
func (q *RootScheduler) Close() error
func (*RootScheduler) Submit ¶
func (q *RootScheduler) Submit(queue, id string, run func(ctx context.Context) error)
func (*RootScheduler) SubmitPeriodicJob ¶
func (*RootScheduler) Wait ¶
func (q *RootScheduler) Wait()
Wait blocks until all worker goroutines have exited. The caller should cancel the context passed to New first, otherwise Wait blocks forever.
func (*RootScheduler) WithQueuePrefix ¶
func (q *RootScheduler) WithQueuePrefix(prefix string) Scheduler
type ScheduleStore ¶
type ScheduleStore interface {
GetLastRun(key string) (time.Time, bool, error)
SetLastRun(key string, t time.Time) error
Close() error
}
ScheduleStore persists the last execution time of periodic jobs.
func NewScheduleStore ¶
func NewScheduleStore(dbPath string) (ScheduleStore, error)
NewScheduleStore creates a bbolt-backed schedule store at the given database path.
type Scheduler ¶
type Scheduler interface {
// WithQueuePrefix creates a new Scheduler that prefixes all queue names with the given prefix.
//
// This is useful to avoid collisions across strategies.
WithQueuePrefix(prefix string) Scheduler
// Submit a job to the queue.
//
// Jobs run concurrently across queues, but never within a queue.
Submit(queue, id string, run func(ctx context.Context) error)
// SubmitPeriodicJob submits a job to the queue that runs immediately, and then periodically after the interval.
//
// Jobs run concurrently across queues, but never within a queue.
SubmitPeriodicJob(queue, id string, interval time.Duration, run func(ctx context.Context) error)
}
Scheduler runs background jobs concurrently across multiple serialised queues.
That is, each queue can have at most one job running at a time, but multiple queues can run concurrently.
Its primary role is to rate limit concurrent background tasks so that we don't DoS the host when, for example, generating git snapshots, GCing git repos, etc.