1package jobs
 2
 3import (
 4	"context"
 5	"sync"
 6)
 7
 8// Job is a job that can be registered with the scheduler.
 9type Job struct {
10	ID     int
11	Runner Runner
12}
13
14// Runner is a job runner.
15type Runner interface {
16	Spec(context.Context) string
17	Func(context.Context) func()
18}
19
20var (
21	mtx  sync.Mutex
22	jobs = make(map[string]*Job, 0)
23)
24
25// Register registers a job.
26func Register(name string, runner Runner) {
27	mtx.Lock()
28	defer mtx.Unlock()
29	jobs[name] = &Job{Runner: runner}
30}
31
32// List returns a map of registered jobs.
33func List() map[string]*Job {
34	mtx.Lock()
35	defer mtx.Unlock()
36	return jobs
37}