Beispiel #1
0
func (build *Build) buildTask(tsk *task) (e error) {
	checksumDir := fmt.Sprintf(ukCACHEDIR+"/%s", tsk.name)
	tsk.started = time.Now()

	for _, cmd := range tsk.commands {
		checksum := cmd.Checksum()

		m := message(pubsub.MessageTasksProvisionTask, build.hostname(), tsk.name)
		m.TaskChecksum = checksum
		m.Message = cmd.LogMsg()

		var cmdErr error

		switch {
		case cmd.cached:
			m.ExecStatus = pubsub.StatusCached
		default:
			m.ExecStatus = pubsub.StatusExecStart
			m.Publish("started")
			status = constants.Status(strings.Join([]string{tsk.name, STARTING}, "."))
			_ = eventNotify(build.Inputs, build.hostname())
			r := &commandRunner{
				build:    build,
				command:  cmd.command,
				dir:      checksumDir,
				taskName: tsk.name,
			}
			cmdErr = r.run()
			if cmdErr == nil {
				status = constants.Status(strings.Join([]string{tsk.name, COMPLETED}, "."))
				_ = eventNotify(build.Inputs, build.hostname())
			}
			m.Error = cmdErr
			m.ExecStatus = pubsub.StatusExecFinished
		}
		m.Publish("finished")

		err := build.addCmdToTaskLog(tsk, checksumDir, checksum, cmdErr)
		switch {
		case cmdErr != nil:
			return cmdErr
		case err != nil:
			return err
		}
	}
	return nil
}
Beispiel #2
0
// This will render the build's template into a package and run all its tasks.
func (b *Build) Run() error {
	pkg, e := b.prepareBuild()
	if e != nil {
		return e
	}
	m := message(pubsub.MessageTasksProvision, b.hostname(), "")
	m.Publish("started")
	templateName := strings.Split(pkg.tasks[0].name, ".")[0]
	status = constants.Status(strings.Join([]string{templateName, RUNNING}, "."))
	_ = eventNotify(b.Inputs, b.hostname())
	for _, task := range pkg.tasks {
		if e = b.buildTask(task); e != nil {
			m.PublishError(e)
			return e
		}
	}
	m.Publish(FINISHED)
	status = constants.Status(strings.Join([]string{templateName, FINISHED}, "."))
	_ = eventNotify(b.Inputs, b.hostname())
	return nil
}