mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-16 18:01:02 +02:00
Implement jobrun package, abstraction for cron-like goroutines.
Unlike cron, there is no overtaking though.
This commit is contained in:
52
cmd/main.go
52
cmd/main.go
@ -4,9 +4,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/zrepl/zrepl/jobrun"
|
||||
"github.com/zrepl/zrepl/rpc"
|
||||
"github.com/zrepl/zrepl/sshbytestream"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Role uint
|
||||
@ -18,6 +21,7 @@ const (
|
||||
|
||||
var conf Config
|
||||
var handler Handler
|
||||
var runner *jobrun.JobRunner
|
||||
|
||||
func main() {
|
||||
|
||||
@ -37,6 +41,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
handler = Handler{}
|
||||
|
||||
runner = jobrun.NewJobRunner()
|
||||
return
|
||||
}
|
||||
app.Commands = []cli.Command{
|
||||
@ -73,7 +79,51 @@ func doSink(c *cli.Context) (err error) {
|
||||
|
||||
func doRun(c *cli.Context) error {
|
||||
|
||||
fmt.Printf("%#v", conf)
|
||||
// Do every pull, do every push
|
||||
// Scheduling
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
runner.Start()
|
||||
}()
|
||||
|
||||
for i := range conf.Pulls {
|
||||
pull := conf.Pulls[i]
|
||||
|
||||
j := jobrun.Job{
|
||||
Name: fmt.Sprintf("pull%d", i),
|
||||
Interval: time.Duration(5 * time.Second),
|
||||
Repeats: true,
|
||||
RunFunc: func() error {
|
||||
fmt.Printf("%v: %#v\n", time.Now(), pull)
|
||||
time.Sleep(10 * time.Second)
|
||||
fmt.Printf("%v: %#v\n", time.Now(), pull)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
runner.AddJob(j)
|
||||
}
|
||||
|
||||
for i := range conf.Pushs {
|
||||
push := conf.Pushs[i]
|
||||
|
||||
j := jobrun.Job{
|
||||
Name: fmt.Sprintf("push%d", i),
|
||||
Interval: time.Duration(5 * time.Second),
|
||||
Repeats: true,
|
||||
RunFunc: func() error {
|
||||
fmt.Printf("%v: %#v\n", time.Now(), push)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
runner.AddJob(j)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user