soft-serve

git clone git://git.lin.moe/fork/soft-serve.git

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