Skip to content

Commit 006ae99

Browse files
Fix multiple tasks of same type only handled once per snowblock config
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
1 parent c511fa1 commit 006ae99

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pkg/snowblock/snowblock.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Snowblock struct {
4343
TaskObjects []api.Task
4444

4545
// TaskRunnerMapping contains the assignments from task objects to a matching task runner.
46-
TaskRunnerMapping map[api.TaskRunner]api.TaskConfiguration
46+
TaskRunnerMapping map[api.TaskRunner][]api.TaskConfiguration
4747

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

6161
// Dispatch handles the processing of the snowblock by dispatching the configured tasks to a registered runner that can
6262
// handle it.
6363
func (s *Snowblock) Dispatch() error {
6464
for runner, instructions := range s.TaskRunnerMapping {
65-
if err := runner.Run(instructions, s.Path); err != nil {
66-
return err
65+
for _, taskConfig := range instructions {
66+
if err := runner.Run(taskConfig, s.Path); err != nil {
67+
return err
68+
}
6769
}
6870
}
6971

@@ -109,7 +111,7 @@ func (s *Snowblock) Validate(taskRunner map[string]api.TaskRunner) error {
109111
for taskName, taskConfigMap := range taskObject {
110112
runner, exists := taskRunner[taskName]
111113
if exists {
112-
s.TaskRunnerMapping[runner] = taskConfigMap
114+
s.TaskRunnerMapping[runner] = append(s.TaskRunnerMapping[runner], taskConfigMap)
113115
continue
114116
}
115117
s.UnsupportedTasks = append(s.UnsupportedTasks, taskName)

0 commit comments

Comments
 (0)