-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_command.go
More file actions
71 lines (55 loc) · 1.78 KB
/
Copy pathtask_command.go
File metadata and controls
71 lines (55 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package plumber
import (
"context"
)
// Creates a NewCommand attached to the current task.
func (t *Task) CreateCommand(command string, args ...string) *Command {
return NewCommand(t, command, args...)
}
// Returns the attached commands to this task.
func (t *Task) GetCommands() []*Command {
return t.commands
}
// Returns the attached commands to this task as a slice of jobs.
func (t *Task) GetCommandJobs() []Job {
j := []Job{}
for _, c := range t.commands {
j = append(j, c.Job())
}
return j
}
// Returns the attached commands to this task as a job to run as sequence depending on their definition order.
func (t *Task) GetCommandJobAsJobSequence() Job {
j := t.GetCommandJobs()
if len(j) == 0 {
return nil
}
return JobSequence(j...)
}
// Returns the attached commands to this task as a job to run as parallel depending on their definition order.
func (t *Task) GetCommandJobAsJobParallel() Job {
j := t.GetCommandJobs()
if len(j) == 0 {
return nil
}
return JobParallel(j...)
}
// Attaches existing commands to this task.
func (t *Task) AddCommands(commands ...*Command) *Task {
t.taskLock.Lock()
t.commands = append(t.commands, commands...)
t.taskLock.Unlock()
return t
}
// Runs the commands that are attached to this task as sequence.
func (t *Task) RunCommandJobAsJobSequence(ctx context.Context) error {
return t.Plumber.runJobs(ctx, t.GetCommandJobAsJobSequence())
}
// Runs the commands that are attached to this task as parallel.
func (t *Task) RunCommandJobAsJobParallel(ctx context.Context) error {
return t.Plumber.runJobs(ctx, t.GetCommandJobAsJobParallel())
}
// Runs the commands that are attached to this task as parallel with the given wrapper.
func (t *Task) RunCommandJob(ctx context.Context, fn TaskJobParserFn) error {
return t.Plumber.runJobs(ctx, fn(t))
}