diff --git a/supfile.go b/supfile.go index ad5e924..1cde8f5 100644 --- a/supfile.go +++ b/supfile.go @@ -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 != "" { diff --git a/task.go b/task.go index af2849a..ec055c0 100644 --- a/task.go +++ b/task.go @@ -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, ©) + } } else { task.Clients = clients - tasks = append(tasks, task) + tasks = append(tasks, &task) } } @@ -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, ©) + } } else { task.Clients = clients + tasks = append(tasks, &task) } - tasks = append(tasks, task) } // Local command. @@ -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 {