Skip to content

Commit

Permalink
Fix command.once and upload/script tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek committed Dec 15, 2015
1 parent ca73d15 commit 2327cb9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
6 changes: 3 additions & 3 deletions supfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func NewSupfile(file string) (*Supfile, error) {
if cmd.Local != "" {
return nil, errors.New("command.local is not supported in Supfile v" + conf.Version)
}
// if cmd.Serial != 0 {
// return nil, errors.New("command.serial is not supported in Supfile v0.2")
// }
if cmd.Serial != 0 {
return nil, errors.New("command.serial is not supported in Supfile v" + conf.Version)
}
}
for _, network := range conf.Networks {
if network.Inventory != "" {
Expand Down
39 changes: 31 additions & 8 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,28 @@ func CreateTasks(cmd *Command, clients []Client, env string) ([]*Task, error) {

// Anything to upload?
for _, upload := range cmd.Upload {
task := &Task{
task := Task{
Run: RemoteTarCommand(upload.Dst),
Input: NewTarStreamReader(upload.Src, upload.Exc, env),
}

if cmd.RunOnce {
if cmd.Once {
task.Clients = []Client{clients[0]}
tasks = append(tasks, task)
tasks = append(tasks, &task)
} else if cmd.Serial > 0 {
// Each "serial" task client group is executed sequentially.
for i := 0; i < len(clients); i += cmd.Serial {
j := i + cmd.Serial
if j > len(clients) {
j = len(clients)
}
copy := task
copy.Clients = clients[i:j]
tasks = append(tasks, &copy)
}
} else {
task.Clients = clients
tasks = append(tasks, task)
tasks = append(tasks, &task)
}
}

Expand All @@ -44,18 +55,30 @@ func CreateTasks(cmd *Command, clients []Client, env string) ([]*Task, error) {
return nil, err
}

task := &Task{
task := Task{
Run: string(data),
}
if cmd.Stdin {
task.Input = os.Stdin
}
if cmd.RunOnce {
if cmd.Once {
task.Clients = []Client{clients[0]}
tasks = append(tasks, &task)
} else if cmd.Serial > 0 {
// Each "serial" task client group is executed sequentially.
for i := 0; i < len(clients); i += cmd.Serial {
j := i + cmd.Serial
if j > len(clients) {
j = len(clients)
}
copy := task
copy.Clients = clients[i:j]
tasks = append(tasks, &copy)
}
} else {
task.Clients = clients
tasks = append(tasks, &task)
}
tasks = append(tasks, task)
}

// Local command.
Expand All @@ -82,7 +105,7 @@ func CreateTasks(cmd *Command, clients []Client, env string) ([]*Task, error) {
if cmd.Stdin {
task.Input = os.Stdin
}
if cmd.RunOnce {
if cmd.Once {
task.Clients = []Client{clients[0]}
tasks = append(tasks, &task)
} else if cmd.Serial > 0 {
Expand Down

0 comments on commit 2327cb9

Please sign in to comment.