Пример #1
0
// Get returns the TaskConfig for the Name
func (c *TaskCollection) Get(name task.Name) types.TaskConfig {
	for _, task := range c.tasks {
		if task.Name().Equal(name) {
			return task
		}
	}
	return nil
}
Пример #2
0
func executeTasks(ctx *context.ExecuteContext, tasks *TaskCollection) error {
	startedTasks := []types.Task{}

	defer func() {
		logging.Log.Debug("stopping tasks")
		for _, task := range reversed(startedTasks) {
			if err := task.Stop(ctx); err != nil {
				logging.Log.Warnf("Failed to stop task %q: %s", task.Name(), err)
			}
		}
	}()

	logging.Log.Debug("executing tasks")
	for _, taskConfig := range tasks.All() {
		resource, err := taskConfig.Resource().Resolve(ctx.Env)
		if err != nil {
			return err
		}
		ctx.Resources.Add(taskConfig.Name().Resource(), resource)

		task := taskConfig.Task(resource)
		startedTasks = append(startedTasks, task)
		start := time.Now()
		logging.Log.WithFields(log.Fields{"time": start, "task": task}).Debug("Start")

		depsModified := hasModifiedDeps(ctx, taskConfig.Dependencies())
		modified, err := task.Run(ctx, depsModified)
		if err != nil {
			return fmt.Errorf("failed to execute task %q: %s", task.Name(), err)
		}
		if modified {
			ctx.SetModified(task.Name())
		}
		logging.Log.WithFields(log.Fields{
			"elapsed": time.Since(start),
			"task":    task,
		}).Debug("Complete")
	}
	return nil
}