package jobs

import (
	"context"
	"time"
)

// Job describes an executable unit that provides its own run cadence.
type Job interface {
	Name() string
	Interval() time.Duration
	Run(context.Context) error
}

var registry []Job

// Register makes a job discoverable by the scheduler. Typically invoked in init.
func Register(job Job) {
	registry = append(registry, job)
}

// All returns a snapshot of the currently registered jobs.
func All() []Job {
	out := make([]Job, len(registry))
	copy(out, registry)
	return out
}
