mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-13 01:39:12 +01:00
parent
0895e02844
commit
aa3865d0a3
@ -31,6 +31,8 @@ func (j *ControlJob) JobName() string {
|
||||
return j.Name
|
||||
}
|
||||
|
||||
func (j *ControlJob) JobType() JobType { return JobTypeControl }
|
||||
|
||||
func (j *ControlJob) JobStatus(ctx context.Context) (*JobStatus, error) {
|
||||
return &JobStatus{Tasks: nil}, nil
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ func (j *LocalJob) JobName() string {
|
||||
return j.Name
|
||||
}
|
||||
|
||||
func (j *LocalJob) JobType() JobType { return JobTypeLocal }
|
||||
|
||||
func (j *LocalJob) JobStart(ctx context.Context) {
|
||||
|
||||
rootLog := ctx.Value(contextKeyLog).(Logger)
|
||||
|
@ -94,6 +94,8 @@ func (j *PullJob) JobName() string {
|
||||
return j.Name
|
||||
}
|
||||
|
||||
func (j *PullJob) JobType() JobType { return JobTypePull }
|
||||
|
||||
func (j *PullJob) JobStart(ctx context.Context) {
|
||||
|
||||
log := ctx.Value(contextKeyLog).(Logger)
|
||||
|
@ -76,6 +76,8 @@ func (j *SourceJob) JobName() string {
|
||||
return j.Name
|
||||
}
|
||||
|
||||
func (j *SourceJob) JobType() JobType { return JobTypeSource }
|
||||
|
||||
func (j *SourceJob) JobStart(ctx context.Context) {
|
||||
|
||||
log := ctx.Value(contextKeyLog).(Logger)
|
||||
|
@ -162,20 +162,25 @@ func parseJob(c JobParsingContext, i map[string]interface{}) (j Job, err error)
|
||||
}
|
||||
}
|
||||
|
||||
jobtype, err := extractStringField(i, "type", true)
|
||||
jobtypeStr, err := extractStringField(i, "type", true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
jobtype, err := ParseUserJobType(jobtypeStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch jobtype {
|
||||
case "pull":
|
||||
case JobTypePull:
|
||||
return parsePullJob(c, name, i)
|
||||
case "source":
|
||||
case JobTypeSource:
|
||||
return parseSourceJob(c, name, i)
|
||||
case "local":
|
||||
case JobTypeLocal:
|
||||
return parseLocalJob(c, name, i)
|
||||
default:
|
||||
return nil, errors.Errorf("unknown job type '%s'", jobtype)
|
||||
panic(fmt.Sprintf("implementation error: unknown job type %s", jobtype))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,10 +28,36 @@ func init() {
|
||||
|
||||
type Job interface {
|
||||
JobName() string
|
||||
JobType() JobType
|
||||
JobStart(ctxt context.Context)
|
||||
JobStatus(ctxt context.Context) (*JobStatus, error)
|
||||
}
|
||||
|
||||
type JobType string
|
||||
|
||||
const (
|
||||
JobTypePull JobType = "pull"
|
||||
JobTypeSource JobType = "source"
|
||||
JobTypeLocal JobType = "local"
|
||||
JobTypeControl JobType = "control"
|
||||
)
|
||||
|
||||
func ParseUserJobType(s string) (JobType, error) {
|
||||
switch s {
|
||||
case "pull":
|
||||
return JobTypePull, nil
|
||||
case "source":
|
||||
return JobTypeSource, nil
|
||||
case "local":
|
||||
return JobTypeLocal, nil
|
||||
}
|
||||
return "", fmt.Errorf("unknown job type '%s'", s)
|
||||
}
|
||||
|
||||
func (j JobType) String() string {
|
||||
return string(j)
|
||||
}
|
||||
|
||||
func doDaemon(cmd *cobra.Command, args []string) {
|
||||
|
||||
conf, err := ParseConfig(rootArgs.configFile)
|
||||
|
Loading…
Reference in New Issue
Block a user