Skip to content

Commit

Permalink
Merge pull request #108 from walter-cd/implement-parallel
Browse files Browse the repository at this point in the history
Implement `parallel' (just alias of run_after)
  • Loading branch information
takahi-i committed Apr 22, 2015
2 parents 2e53e91 + 3e756b2 commit 181d9b6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -94,6 +94,27 @@ The following is the parameter of Shell script stage.
|:----------------:|:----------:|:--------------------------------------:|
| file | false | shell script file run in the stage |

## Parallel stages

You can set child stages and run these stages in parallel like this.

```yaml
pipeline:
- name: parallel stages
parallel:
- name: parallel command 1
type: command
command: parallel command 1
- name: parallel command 2
type: command
command: parallel command 2
- name: parallel command 3
type: command
command: parallel command 3
```

`parallel command 1`, `parallel command 2` and `parallel command 3` are executed in parallel.

## Cleanup pipeline

Walter configuraiton can have one **cleanup** block; cleanup is another pipeline which needs to be executed after a pipeline has either failed or passed.
Expand Down
13 changes: 10 additions & 3 deletions config/parser.go
Expand Up @@ -219,9 +219,16 @@ func mapStage(stageMap map[interface{}]interface{}, envs *EnvVariables) (stages.
}
}

if runAfters := stageMap["run_after"]; runAfters != nil {
for _, runAfter := range runAfters.([]interface{}) {
childStage, err := mapStage(runAfter.(map[interface{}]interface{}), envs)
parallelStages := stageMap["parallel"]
if parallelStages == nil {
if parallelStages = stageMap["run_after"]; parallelStages != nil {
log.Warn("`run_after' will be obsoleted in near future. Use `parallel' instead.")
}
}

if parallelStages != nil {
for _, parallelStages := range parallelStages.([]interface{}) {
childStage, err := mapStage(parallelStages.(map[interface{}]interface{}), envs)
if err != nil {
return nil, err
}
Expand Down
30 changes: 30 additions & 0 deletions config/parser_test.go
Expand Up @@ -67,6 +67,24 @@ func TestParseConfWithChildren(t *testing.T) {
assert.Equal(t, 2, childStages.Len())
}

func TestParseConfWithParallel(t *testing.T) {
configData := ReadConfigBytes([]byte(`pipeline:
- name: parallel stages
parallel:
- name: parallel command 1
type: command
command: echo "hello, world, parallel command 1"
- name: parallel command 2
type: command
command: echo "hello, world, parallel command 2"`))
result, err := Parse(configData)
assert.Equal(t, 1, result.Pipeline.Size())
assert.Nil(t, err)

childStages := result.Pipeline.Stages.Front().Value.(stages.Stage).GetChildStages()
assert.Equal(t, 2, childStages.Len())
}

func TestParseConfDefaultStageTypeIsCommand(t *testing.T) {
configData := ReadConfigBytes([]byte(`pipeline:
- name: command_stage_1
Expand Down Expand Up @@ -148,6 +166,18 @@ func TestParseConfWithInvalidChildStage(t *testing.T) {
assert.NotNil(t, err)
}

func TestParseConfWithInvalidParallelStage(t *testing.T) {
configData := ReadConfigBytes([]byte(`pipeline:
- name: parallel stages
parallel:
- name: parallel command 1
type: xxxxx
`))
result, err := Parse(configData)
assert.Nil(t, result)
assert.NotNil(t, err)
}

func TestParseConfWithServiceBlock(t *testing.T) {
configData := ReadConfigBytes([]byte(`
service:
Expand Down

0 comments on commit 181d9b6

Please sign in to comment.