jobrun/cmd: implement jobrun.Job for config objects
This commit is contained in:
+6
-20
@@ -2,12 +2,12 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/zrepl/zrepl/jobrun"
|
||||
"github.com/zrepl/zrepl/zfs"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var AutosnapCmd = &cobra.Command{
|
||||
@@ -22,12 +22,7 @@ func init() {
|
||||
|
||||
func cmdAutosnap(cmd *cobra.Command, args []string) {
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
runner.Start()
|
||||
}()
|
||||
r := jobrun.NewJobRunner(log)
|
||||
|
||||
if len(args) < 1 {
|
||||
log.Printf("must specify exactly one job as positional argument")
|
||||
@@ -40,18 +35,9 @@ func cmdAutosnap(cmd *cobra.Command, args []string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
job := jobrun.JobMetadata{
|
||||
Name: snap.JobName,
|
||||
RepeatStrategy: snap.Interval,
|
||||
RunFunc: func(log jobrun.Logger) error {
|
||||
log.Printf("doing autosnap: %v", snap)
|
||||
ctx := AutosnapContext{snap}
|
||||
return doAutosnap(ctx, log)
|
||||
},
|
||||
}
|
||||
runner.AddJob(job)
|
||||
r.AddJob(snap)
|
||||
|
||||
wg.Wait()
|
||||
r.Wait()
|
||||
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -49,14 +49,14 @@ type SSHTransport struct {
|
||||
}
|
||||
|
||||
type Push struct {
|
||||
JobName string // for use with jobrun package
|
||||
jobName string // for use with jobrun package
|
||||
To *Remote
|
||||
Filter zfs.DatasetFilter
|
||||
InitialReplPolicy InitialReplPolicy
|
||||
RepeatStrategy jobrun.RepeatStrategy
|
||||
}
|
||||
type Pull struct {
|
||||
JobName string // for use with jobrun package
|
||||
jobName string // for use with jobrun package
|
||||
From *Remote
|
||||
Mapping DatasetMapFilter
|
||||
InitialReplPolicy InitialReplPolicy
|
||||
@@ -64,14 +64,14 @@ type Pull struct {
|
||||
}
|
||||
|
||||
type Prune struct {
|
||||
JobName string // for use with jobrun package
|
||||
jobName string // for use with jobrun package
|
||||
DatasetFilter zfs.DatasetFilter
|
||||
SnapshotFilter zfs.FilesystemVersionFilter
|
||||
RetentionPolicy *RetentionGrid // TODO abstract interface to support future policies?
|
||||
}
|
||||
|
||||
type Autosnap struct {
|
||||
JobName string // for use with jobrun package
|
||||
jobName string // for use with jobrun package
|
||||
Prefix string
|
||||
Interval jobrun.RepeatStrategy
|
||||
DatasetFilter zfs.DatasetFilter
|
||||
@@ -230,7 +230,7 @@ func parsePushs(v interface{}, rl remoteLookup) (p map[string]*Push, err error)
|
||||
To: toRemote,
|
||||
}
|
||||
|
||||
if push.JobName, err = fullJobName(JobSectionPush, name); err != nil {
|
||||
if push.jobName, err = fullJobName(JobSectionPush, name); err != nil {
|
||||
return
|
||||
}
|
||||
if push.Filter, err = parseDatasetMapFilter(e.Filter, true); err != nil {
|
||||
@@ -289,7 +289,7 @@ func parsePulls(v interface{}, rl remoteLookup) (p map[string]*Pull, err error)
|
||||
pull := &Pull{
|
||||
From: fromRemote,
|
||||
}
|
||||
if pull.JobName, err = fullJobName(JobSectionPull, name); err != nil {
|
||||
if pull.jobName, err = fullJobName(JobSectionPull, name); err != nil {
|
||||
return
|
||||
}
|
||||
if pull.Mapping, err = parseDatasetMapFilter(e.Mapping, false); err != nil {
|
||||
@@ -507,7 +507,7 @@ func parsePrune(e map[string]interface{}, name string) (prune *Prune, err error)
|
||||
|
||||
prune = &Prune{}
|
||||
|
||||
if prune.JobName, err = fullJobName(JobSectionPrune, name); err != nil {
|
||||
if prune.jobName, err = fullJobName(JobSectionPrune, name); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -705,7 +705,7 @@ func parseAutosnap(m interface{}, name string) (a *Autosnap, err error) {
|
||||
|
||||
a = &Autosnap{}
|
||||
|
||||
if a.JobName, err = fullJobName(JobSectionAutosnap, name); err != nil {
|
||||
if a.jobName, err = fullJobName(JobSectionAutosnap, name); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zrepl/zrepl/jobrun"
|
||||
)
|
||||
|
||||
func (p *Pull) JobName() string {
|
||||
return p.jobName
|
||||
}
|
||||
|
||||
func (p *Pull) JobDo(log jobrun.Logger) (err error) {
|
||||
return jobPull(p, log)
|
||||
}
|
||||
|
||||
func (p *Pull) JobRepeatStrategy() jobrun.RepeatStrategy {
|
||||
return p.RepeatStrategy
|
||||
}
|
||||
|
||||
func (a *Autosnap) JobName() string {
|
||||
return a.jobName
|
||||
}
|
||||
|
||||
func (a *Autosnap) JobDo(log jobrun.Logger) (err error) {
|
||||
return doAutosnap(AutosnapContext{a}, log)
|
||||
}
|
||||
|
||||
func (a *Autosnap) JobRepeatStrategy() jobrun.RepeatStrategy {
|
||||
return a.Interval
|
||||
}
|
||||
|
||||
func (p *Prune) JobName() string {
|
||||
return p.jobName
|
||||
}
|
||||
|
||||
func (p *Prune) JobDo(log jobrun.Logger) (err error) {
|
||||
return doPrune(PruneContext{p, time.Now(), false}, log)
|
||||
}
|
||||
|
||||
func (p *Prune) JobRepeatStrategy() jobrun.RepeatStrategy {
|
||||
return p.Repeat
|
||||
}
|
||||
@@ -13,7 +13,6 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/zrepl/zrepl/jobrun"
|
||||
"golang.org/x/sys/unix"
|
||||
"io"
|
||||
golog "log"
|
||||
@@ -29,7 +28,6 @@ type Logger interface {
|
||||
// global state / facilities
|
||||
var (
|
||||
conf Config
|
||||
runner *jobrun.JobRunner
|
||||
logFlags int = golog.LUTC | golog.Ldate | golog.Ltime
|
||||
logOut io.Writer
|
||||
log Logger
|
||||
@@ -97,8 +95,6 @@ func initConfig() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
jobrunLogger := golog.New(os.Stderr, "jobrun ", logFlags)
|
||||
runner = jobrun.NewJobRunner(jobrunLogger)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user