func (*Executor) Start(f def.Formula, id def.JobID, stdin io.Reader, journal io.Writer) def.Job { job := basicjob.New(id) go func() { close(job.WaitChan) }() return job }
func (e *Executor) Start(f def.Formula, id def.JobID, stdin io.Reader, journal io.Writer) def.Job { // Prepare the forumla for execution on this host def.ValidateAll(&f) job := basicjob.New(id) jobReady := make(chan struct{}) go func() { // Run the formula in a temporary directory flak.WithDir(func(dir string) { // spool our output to a muxed stream var strm streamer.Mux strm = streamer.CborFileMux(filepath.Join(dir, "log")) outS := strm.Appender(1) errS := strm.Appender(2) job.Streams = strm defer func() { // Regardless of how the job ends (or even if it fails the remaining setup), output streams must be terminated. outS.Close() errS.Close() }() // Job is ready to stream process output close(jobReady) // Set up a logger. Tag all messages with this jobid. logger := log15.New(log15.Ctx{"JobID": id}) logger.SetHandler(log15.StreamHandler(journal, log15.TerminalFormat())) job.Result = e.Run(f, job, dir, stdin, outS, errS, logger) }, e.workspacePath, "job", string(job.Id())) // Directory is clean; job complete close(job.WaitChan) }() <-jobReady return job }