Пример #1
0
func (self *wrapper) runHook(hook *JobConfig, hookname, name, stdout, stderr string) {

	job, err := self.job.getConfig(*hook, nil, nil)
	if err != nil {
		self.c <- &ErrorEvent{}
		return
	}

	job.Args = append(job.Args, stdout, stderr)

	now := time.Now()
	cmd := exec.New(*job)
	self.c <- &StartEvent{
		id:   self.job.id,
		name: fmt.Sprintf("%s %s hook", name, hookname),
		time: now,
	}

	err = cmd.Start(context.Background())

	self.c <- &FinishEvent{
		id:       self.job.id,
		name:     fmt.Sprintf("%s %s hook", name, hookname),
		duration: time.Since(now),
		err:      err,
	}

}
Пример #2
0
func (self *CronJob) initExecutor(stdout io.Writer, stderr io.Writer) error {

	return self.withLock(func() error {
		conf, e := self.getConfig(self.config.JobConfig, stdout, stderr)
		if e != nil {
			return e
		}

		self.cmd = exec.New(*conf)
		self.running = true
		return nil
	})

}