-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
wait.go
82 lines (73 loc) · 1.68 KB
/
wait.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package commands
import (
"time"
"github.com/argoproj/pkg/stats"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func NewWaitCommand() *cobra.Command {
var command = cobra.Command{
Use: "wait",
Short: "wait for main container to finish and save artifacts",
Run: func(cmd *cobra.Command, args []string) {
err := waitContainer()
if err != nil {
log.Fatalf("%+v", err)
}
},
}
return &command
}
func waitContainer() error {
wfExecutor := initExecutor()
defer wfExecutor.HandleError()
defer stats.LogStats()
stats.StartStatsTicker(5 * time.Minute)
defer func() {
// Killing sidecar containers
err := wfExecutor.KillSidecars()
if err != nil {
log.Errorf("Failed to kill sidecars: %s", err.Error())
}
}()
// Wait for main container to complete
waitErr := wfExecutor.Wait()
if waitErr != nil {
wfExecutor.AddError(waitErr)
// do not return here so we can still try to kill sidecars & save outputs
}
// Saving logs
logArt, err := wfExecutor.SaveLogs()
if err != nil {
wfExecutor.AddError(err)
return err
}
// Saving output parameters
err = wfExecutor.SaveParameters()
if err != nil {
wfExecutor.AddError(err)
return err
}
// Saving output artifacts
err = wfExecutor.SaveArtifacts()
if err != nil {
wfExecutor.AddError(err)
return err
}
// Capture output script result
err = wfExecutor.CaptureScriptResult()
if err != nil {
wfExecutor.AddError(err)
return err
}
err = wfExecutor.AnnotateOutputs(logArt)
if err != nil {
wfExecutor.AddError(err)
return err
}
// To prevent the workflow step from completing successfully, return the error occurred during wait.
if waitErr != nil {
return waitErr
}
return nil
}