-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
wait.go
72 lines (59 loc) · 1.66 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
package commands
import (
"context"
"time"
"github.com/argoproj/pkg/stats"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func NewWaitCommand() *cobra.Command {
command := cobra.Command{
Use: "wait",
Short: "wait for main container to finish and save artifacts",
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
err := waitContainer(ctx)
if err != nil {
log.Fatalf("%+v", err)
}
},
}
return &command
}
func waitContainer(ctx context.Context) error {
wfExecutor := initExecutor()
// Don't allow cancellation to impact capture of results, parameters, artifacts, or defers.
bgCtx := context.Background()
defer wfExecutor.HandleError(bgCtx) // Must be placed at the bottom of defers stack.
defer wfExecutor.FinalizeOutput(bgCtx) // Ensures the LabelKeyReportOutputsCompleted is set to true.
defer stats.LogStats()
stats.StartStatsTicker(5 * time.Minute)
// Wait for main container to complete
err := wfExecutor.Wait(ctx)
if err != nil {
wfExecutor.AddError(err)
}
// Capture output script result
err = wfExecutor.CaptureScriptResult(bgCtx)
if err != nil {
wfExecutor.AddError(err)
}
// Saving output parameters
err = wfExecutor.SaveParameters(bgCtx)
if err != nil {
wfExecutor.AddError(err)
}
// Saving output artifacts
err = wfExecutor.SaveArtifacts(bgCtx)
if err != nil {
wfExecutor.AddError(err)
}
// Save log artifacts
logArtifacts := wfExecutor.SaveLogs(bgCtx)
// Try to upsert TaskResult. If it fails, we will try to update the Pod's Annotations
err = wfExecutor.ReportOutputs(bgCtx, logArtifacts)
if err != nil {
wfExecutor.AddError(err)
}
return wfExecutor.HasError()
}