mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-25 09:54:47 +01:00
jobrun: rename to jobmetadata
This commit is contained in:
parent
6ab05ee1fa
commit
3070d156a3
@ -40,7 +40,7 @@ func cmdAutosnap(cmd *cobra.Command, args []string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
job := jobrun.Job{
|
job := jobrun.JobMetadata{
|
||||||
Name: snap.JobName,
|
Name: snap.JobName,
|
||||||
RepeatStrategy: snap.Interval,
|
RepeatStrategy: snap.Interval,
|
||||||
RunFunc: func(log jobrun.Logger) error {
|
RunFunc: func(log jobrun.Logger) error {
|
||||||
|
@ -92,10 +92,10 @@ func cmdRun(cmd *cobra.Command, args []string) {
|
|||||||
runner.Start()
|
runner.Start()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
jobs := make([]jobrun.Job, len(conf.Pulls)+len(conf.Pushs))
|
jobs := make([]jobrun.JobMetadata, len(conf.Pulls)+len(conf.Pushs))
|
||||||
i := 0
|
i := 0
|
||||||
for _, pull := range conf.Pulls {
|
for _, pull := range conf.Pulls {
|
||||||
jobs[i] = jobrun.Job{
|
jobs[i] = jobrun.JobMetadata{
|
||||||
Name: fmt.Sprintf("pull.%d", i),
|
Name: fmt.Sprintf("pull.%d", i),
|
||||||
RepeatStrategy: pull.RepeatStrategy,
|
RepeatStrategy: pull.RepeatStrategy,
|
||||||
RunFunc: func(log jobrun.Logger) error {
|
RunFunc: func(log jobrun.Logger) error {
|
||||||
@ -106,7 +106,7 @@ func cmdRun(cmd *cobra.Command, args []string) {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
for _, push := range conf.Pushs {
|
for _, push := range conf.Pushs {
|
||||||
jobs[i] = jobrun.Job{
|
jobs[i] = jobrun.JobMetadata{
|
||||||
Name: fmt.Sprintf("push.%d", i),
|
Name: fmt.Sprintf("push.%d", i),
|
||||||
RepeatStrategy: push.RepeatStrategy,
|
RepeatStrategy: push.RepeatStrategy,
|
||||||
RunFunc: func(log jobrun.Logger) error {
|
RunFunc: func(log jobrun.Logger) error {
|
||||||
|
@ -18,7 +18,7 @@ func (l jobLogger) Printf(format string, v ...interface{}) {
|
|||||||
l.MainLog.Printf(fmt.Sprintf("job[%s]: %s", l.JobName, format), v...)
|
l.MainLog.Printf(fmt.Sprintf("job[%s]: %s", l.JobName, format), v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Job struct {
|
type JobMetadata struct {
|
||||||
Name string
|
Name string
|
||||||
RunFunc func(log Logger) (err error)
|
RunFunc func(log Logger) (err error)
|
||||||
LastStart time.Time
|
LastStart time.Time
|
||||||
@ -41,34 +41,34 @@ type RepeatStrategy interface {
|
|||||||
|
|
||||||
type JobRunner struct {
|
type JobRunner struct {
|
||||||
logger Logger
|
logger Logger
|
||||||
notificationChan chan Job
|
notificationChan chan JobMetadata
|
||||||
newJobChan chan Job
|
newJobChan chan JobMetadata
|
||||||
finishedJobChan chan Job
|
finishedJobChan chan JobMetadata
|
||||||
scheduleTimer <-chan time.Time
|
scheduleTimer <-chan time.Time
|
||||||
pending map[string]Job
|
pending map[string]JobMetadata
|
||||||
running map[string]Job
|
running map[string]JobMetadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJobRunner(logger Logger) *JobRunner {
|
func NewJobRunner(logger Logger) *JobRunner {
|
||||||
return &JobRunner{
|
return &JobRunner{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
notificationChan: make(chan Job),
|
notificationChan: make(chan JobMetadata),
|
||||||
newJobChan: make(chan Job),
|
newJobChan: make(chan JobMetadata),
|
||||||
finishedJobChan: make(chan Job),
|
finishedJobChan: make(chan JobMetadata),
|
||||||
pending: make(map[string]Job),
|
pending: make(map[string]JobMetadata),
|
||||||
running: make(map[string]Job),
|
running: make(map[string]JobMetadata),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *JobRunner) AddJobChan() chan<- Job {
|
func (r *JobRunner) AddJobChan() chan<- JobMetadata {
|
||||||
return r.newJobChan
|
return r.newJobChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *JobRunner) AddJob(j Job) {
|
func (r *JobRunner) AddJob(j JobMetadata) {
|
||||||
r.newJobChan <- j
|
r.newJobChan <- j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *JobRunner) NotificationChan() <-chan Job {
|
func (r *JobRunner) NotificationChan() <-chan JobMetadata {
|
||||||
return r.notificationChan
|
return r.notificationChan
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ loop:
|
|||||||
r.running[jobName] = job
|
r.running[jobName] = job
|
||||||
job.LastStart = now
|
job.LastStart = now
|
||||||
|
|
||||||
go func(job Job) {
|
go func(job JobMetadata) {
|
||||||
jobLog := jobLogger{r.logger, job.Name}
|
jobLog := jobLogger{r.logger, job.Name}
|
||||||
if err := job.RunFunc(jobLog); err != nil {
|
if err := job.RunFunc(jobLog); err != nil {
|
||||||
job.LastError = err
|
job.LastError = err
|
||||||
|
Loading…
Reference in New Issue
Block a user