Skip to content

Commit

Permalink
Fix multiple tasks of same type only handled once per snowblock config
Browse files Browse the repository at this point in the history
When a task is defined multiple times within the same snowblock
configuration file, only the last object was processed while any object
before has been ignored.
The root cause was the `pkg/snowblock.TaskRunnerMapping` (1) custom type
that only accepted one `pkg/api.TaskConfiguration` (2) object.
Therefore any parsed task object of the same type was overriden (2) by
tasks that are parsed after that task resulted in missing tasks.

Before this commit, running this example configuration has not processed
the first `clean` task but only the second one:

```json
[
  {
    "clean": ["~/desktop/failure"]
  },
  {
    "link": {
      "~/desktop/success/config.json": {
        "create": true,
        "path": "config.json"
      }
    }
  },
  {
    "clean": ["~/desktop/success"]
  },
]
```

To fix the problem the `pkg/snowblock.TaskRunnerMapping` type now
accepts multiple `pkg/api.TaskConfiguration` (2) objects
(`TaskRunnerMapping map[api.TaskRunner][]api.TaskConfiguration`) instead
of only one so the previous object won't be overridden.

References:
  (1) https://github.com/arcticicestudio/snowsaw/blob/efdff96ec01f26bbf0a0d75bb9aab4cb86f023e8/pkg/snowblock/snowblock.go#L46
  (2) https://github.com/arcticicestudio/snowsaw/blob/988073b1bde8d7db4b40f259e99d218c959bba8f/pkg/api/snowblock/task.go#L18
  (3) https://github.com/arcticicestudio/snowsaw/blob/efdff96ec01f26bbf0a0d75bb9aab4cb86f023e8/pkg/snowblock/snowblock.go#L112

Epic: GH-33
Fixes GH-76
  • Loading branch information
arcticicestudio committed Jul 15, 2019
1 parent c511fa1 commit 006ae99
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/snowblock/snowblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Snowblock struct {
TaskObjects []api.Task

// TaskRunnerMapping contains the assignments from task objects to a matching task runner.
TaskRunnerMapping map[api.TaskRunner]api.TaskConfiguration
TaskRunnerMapping map[api.TaskRunner][]api.TaskConfiguration

// UnsupportedTasks is a list of task names that are not supported by an registered task runner.
UnsupportedTasks []api.TaskConfiguration
Expand All @@ -54,16 +54,18 @@ func NewSnowblock(path string) *Snowblock {
return &Snowblock{
Path: path,
TaskObjects: make([]api.Task, 0),
TaskRunnerMapping: make(map[api.TaskRunner]api.TaskConfiguration),
TaskRunnerMapping: make(map[api.TaskRunner][]api.TaskConfiguration),
}
}

// Dispatch handles the processing of the snowblock by dispatching the configured tasks to a registered runner that can
// handle it.
func (s *Snowblock) Dispatch() error {
for runner, instructions := range s.TaskRunnerMapping {
if err := runner.Run(instructions, s.Path); err != nil {
return err
for _, taskConfig := range instructions {
if err := runner.Run(taskConfig, s.Path); err != nil {
return err
}
}
}

Expand Down Expand Up @@ -109,7 +111,7 @@ func (s *Snowblock) Validate(taskRunner map[string]api.TaskRunner) error {
for taskName, taskConfigMap := range taskObject {
runner, exists := taskRunner[taskName]
if exists {
s.TaskRunnerMapping[runner] = taskConfigMap
s.TaskRunnerMapping[runner] = append(s.TaskRunnerMapping[runner], taskConfigMap)
continue
}
s.UnsupportedTasks = append(s.UnsupportedTasks, taskName)
Expand Down

0 comments on commit 006ae99

Please sign in to comment.