forked from argoproj/argo-workflows
/
wait.go
66 lines (60 loc) · 1.3 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
package commands
import (
"time"
"github.com/argoproj/pkg/stats"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
RootCmd.AddCommand(waitCmd)
}
var waitCmd = &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)
}
},
}
func waitContainer() error {
wfExecutor := initExecutor()
defer wfExecutor.HandleError()
defer stats.LogStats()
stats.StartStatsTicker(5 * time.Minute)
// Wait for main container to complete and kill sidecars
err := wfExecutor.Wait()
if err != nil {
wfExecutor.AddError(err)
// do not return here so we can still try to save outputs
}
logArt, err := wfExecutor.SaveLogs()
if err != nil {
wfExecutor.AddError(err)
return err
}
err = wfExecutor.SaveArtifacts()
if err != nil {
wfExecutor.AddError(err)
return err
}
// Saving output parameters
err = wfExecutor.SaveParameters()
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
}
return nil
}