mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-09 15:58:33 +01:00
cmd: remove RunCmd
This commit is contained in:
parent
3070d156a3
commit
582ae83da3
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -19,12 +18,6 @@ var runArgs struct {
|
||||
once bool
|
||||
}
|
||||
|
||||
var RunCmd = &cobra.Command{
|
||||
Use: "run",
|
||||
Short: "run push & pull replication",
|
||||
Run: cmdRun,
|
||||
}
|
||||
|
||||
var PushCmd = &cobra.Command{
|
||||
Use: "push",
|
||||
Short: "run push job (first positional argument)",
|
||||
@ -38,10 +31,6 @@ var PullCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(RunCmd)
|
||||
RunCmd.Flags().BoolVar(&runArgs.once, "once", false, "run jobs only once, regardless of configured repeat behavior")
|
||||
RunCmd.Flags().StringVar(&runArgs.job, "job", "", "run only the given job")
|
||||
|
||||
RootCmd.AddCommand(PushCmd)
|
||||
RootCmd.AddCommand(PullCmd)
|
||||
}
|
||||
@ -83,65 +72,6 @@ func cmdPull(cmd *cobra.Command, args []string) {
|
||||
|
||||
}
|
||||
|
||||
func cmdRun(cmd *cobra.Command, args []string) {
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
runner.Start()
|
||||
}()
|
||||
|
||||
jobs := make([]jobrun.JobMetadata, len(conf.Pulls)+len(conf.Pushs))
|
||||
i := 0
|
||||
for _, pull := range conf.Pulls {
|
||||
jobs[i] = jobrun.JobMetadata{
|
||||
Name: fmt.Sprintf("pull.%d", i),
|
||||
RepeatStrategy: pull.RepeatStrategy,
|
||||
RunFunc: func(log jobrun.Logger) error {
|
||||
log.Printf("doing pull: %v", pull)
|
||||
return jobPull(pull, log)
|
||||
},
|
||||
}
|
||||
i++
|
||||
}
|
||||
for _, push := range conf.Pushs {
|
||||
jobs[i] = jobrun.JobMetadata{
|
||||
Name: fmt.Sprintf("push.%d", i),
|
||||
RepeatStrategy: push.RepeatStrategy,
|
||||
RunFunc: func(log jobrun.Logger) error {
|
||||
log.Printf("doing push: %v", push)
|
||||
return jobPush(push, log)
|
||||
},
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
for _, j := range jobs {
|
||||
if runArgs.once {
|
||||
j.RepeatStrategy = jobrun.NoRepeatStrategy{}
|
||||
}
|
||||
if runArgs.job != "" {
|
||||
if runArgs.job == j.Name {
|
||||
runner.AddJob(j)
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
runner.AddJob(j)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case job := <-runner.NotificationChan():
|
||||
log.Printf("job %s reported error: %v\n", job.Name, job.LastError)
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
}
|
||||
|
||||
type localPullACL struct{}
|
||||
|
||||
func (a localPullACL) Filter(p *zfs.DatasetPath) (pass bool, err error) {
|
||||
|
Loading…
Reference in New Issue
Block a user