forked from vmware-archive/atc
/
try_step.go
48 lines (41 loc) · 999 Bytes
/
try_step.go
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
package exec
import (
"os"
"github.com/concourse/atc/worker"
)
// TryStep wraps another step, ignores its errors, and always succeeds.
type TryStep struct {
step StepFactory
runStep Step
}
// Try constructs a TryStep factory.
func Try(step StepFactory) TryStep {
return TryStep{
step: step,
}
}
// Using constructs a *TryStep.
func (ts TryStep) Using(prev Step, repo *worker.ArtifactRepository) Step {
ts.runStep = ts.step.Using(prev, repo)
return &ts
}
// Run runs the nested step, and always returns nil, ignoring the nested step's
// error.
func (ts *TryStep) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
err := ts.runStep.Run(signals, ready)
if err == ErrInterrupted {
return err
}
return nil
}
// Result indicates Success as true, and delegates everything else to the
// nested step.
func (ts *TryStep) Result(x interface{}) bool {
switch v := x.(type) {
case *Success:
*v = Success(true)
return true
default:
return ts.runStep.Result(x)
}
}