mirror of
https://github.com/zrepl/zrepl.git
synced 2025-06-25 20:21:30 +02:00
cmd: run: select job to run
This commit is contained in:
parent
d8adce6110
commit
93d098162e
35
cmd/main.go
35
cmd/main.go
@ -91,6 +91,9 @@ func main() {
|
|||||||
Aliases: []string{"r"},
|
Aliases: []string{"r"},
|
||||||
Usage: "do replication",
|
Usage: "do replication",
|
||||||
Action: cmdRun,
|
Action: cmdRun,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "job"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,9 +147,6 @@ func cmdStdinServer(c *cli.Context) (err error) {
|
|||||||
|
|
||||||
func cmdRun(c *cli.Context) error {
|
func cmdRun(c *cli.Context) error {
|
||||||
|
|
||||||
// Do every pull, do every push
|
|
||||||
// Scheduling
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
@ -154,10 +154,10 @@ func cmdRun(c *cli.Context) error {
|
|||||||
runner.Start()
|
runner.Start()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for i := range conf.Pulls {
|
jobs := make([]jobrun.Job, len(conf.Pulls)+len(conf.Pushs))
|
||||||
pull := conf.Pulls[i]
|
i := 0
|
||||||
|
for _, pull := range conf.Pulls {
|
||||||
j := jobrun.Job{
|
jobs[i] = jobrun.Job{
|
||||||
Name: fmt.Sprintf("pull%d", i),
|
Name: fmt.Sprintf("pull%d", i),
|
||||||
Interval: time.Duration(5 * time.Second),
|
Interval: time.Duration(5 * time.Second),
|
||||||
Repeats: true,
|
Repeats: true,
|
||||||
@ -166,14 +166,10 @@ func cmdRun(c *cli.Context) error {
|
|||||||
return jobPull(pull, c, log)
|
return jobPull(pull, c, log)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
i++
|
||||||
runner.AddJob(j)
|
|
||||||
}
|
}
|
||||||
|
for _, push := range conf.Pushs {
|
||||||
for i := range conf.Pushs {
|
jobs[i] = jobrun.Job{
|
||||||
push := conf.Pushs[i]
|
|
||||||
|
|
||||||
j := jobrun.Job{
|
|
||||||
Name: fmt.Sprintf("push%d", i),
|
Name: fmt.Sprintf("push%d", i),
|
||||||
Interval: time.Duration(5 * time.Second),
|
Interval: time.Duration(5 * time.Second),
|
||||||
Repeats: true,
|
Repeats: true,
|
||||||
@ -182,14 +178,23 @@ func cmdRun(c *cli.Context) error {
|
|||||||
return jobPush(push, c, log)
|
return jobPush(push, c, log)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, j := range jobs {
|
||||||
|
if c.IsSet("job") {
|
||||||
|
if c.String("job") == j.Name {
|
||||||
|
runner.AddJob(j)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
runner.AddJob(j)
|
runner.AddJob(j)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case job := <-runner.NotificationChan():
|
case job := <-runner.NotificationChan():
|
||||||
log.Printf("notificaiton on job %s: error=%v\n", job.Name, job.LastError)
|
log.Printf("job %s reported error: %v\n", job.Name, job.LastError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user