jobrun: rename to jobmetadata

This commit is contained in:
Christian Schwarz 2017-09-01 14:10:12 +02:00
parent 6ab05ee1fa
commit 3070d156a3
3 changed files with 19 additions and 19 deletions

View File

@ -40,7 +40,7 @@ func cmdAutosnap(cmd *cobra.Command, args []string) {
os.Exit(1)
}
job := jobrun.Job{
job := jobrun.JobMetadata{
Name: snap.JobName,
RepeatStrategy: snap.Interval,
RunFunc: func(log jobrun.Logger) error {

View File

@ -92,10 +92,10 @@ func cmdRun(cmd *cobra.Command, args []string) {
runner.Start()
}()
jobs := make([]jobrun.Job, len(conf.Pulls)+len(conf.Pushs))
jobs := make([]jobrun.JobMetadata, len(conf.Pulls)+len(conf.Pushs))
i := 0
for _, pull := range conf.Pulls {
jobs[i] = jobrun.Job{
jobs[i] = jobrun.JobMetadata{
Name: fmt.Sprintf("pull.%d", i),
RepeatStrategy: pull.RepeatStrategy,
RunFunc: func(log jobrun.Logger) error {
@ -106,7 +106,7 @@ func cmdRun(cmd *cobra.Command, args []string) {
i++
}
for _, push := range conf.Pushs {
jobs[i] = jobrun.Job{
jobs[i] = jobrun.JobMetadata{
Name: fmt.Sprintf("push.%d", i),
RepeatStrategy: push.RepeatStrategy,
RunFunc: func(log jobrun.Logger) error {

View File

@ -18,7 +18,7 @@ func (l jobLogger) Printf(format string, v ...interface{}) {
l.MainLog.Printf(fmt.Sprintf("job[%s]: %s", l.JobName, format), v...)
}
type Job struct {
type JobMetadata struct {
Name string
RunFunc func(log Logger) (err error)
LastStart time.Time
@ -41,34 +41,34 @@ type RepeatStrategy interface {
type JobRunner struct {
logger Logger
notificationChan chan Job
newJobChan chan Job
finishedJobChan chan Job
notificationChan chan JobMetadata
newJobChan chan JobMetadata
finishedJobChan chan JobMetadata
scheduleTimer <-chan time.Time
pending map[string]Job
running map[string]Job
pending map[string]JobMetadata
running map[string]JobMetadata
}
func NewJobRunner(logger Logger) *JobRunner {
return &JobRunner{
logger: logger,
notificationChan: make(chan Job),
newJobChan: make(chan Job),
finishedJobChan: make(chan Job),
pending: make(map[string]Job),
running: make(map[string]Job),
notificationChan: make(chan JobMetadata),
newJobChan: make(chan JobMetadata),
finishedJobChan: make(chan JobMetadata),
pending: make(map[string]JobMetadata),
running: make(map[string]JobMetadata),
}
}
func (r *JobRunner) AddJobChan() chan<- Job {
func (r *JobRunner) AddJobChan() chan<- JobMetadata {
return r.newJobChan
}
func (r *JobRunner) AddJob(j Job) {
func (r *JobRunner) AddJob(j JobMetadata) {
r.newJobChan <- j
}
func (r *JobRunner) NotificationChan() <-chan Job {
func (r *JobRunner) NotificationChan() <-chan JobMetadata {
return r.notificationChan
}
@ -138,7 +138,7 @@ loop:
r.running[jobName] = job
job.LastStart = now
go func(job Job) {
go func(job JobMetadata) {
jobLog := jobLogger{r.logger, job.Name}
if err := job.RunFunc(jobLog); err != nil {
job.LastError = err