Skip to content

Commit

Permalink
chore(example): Add watch timeout and print out workflow status messa…
Browse files Browse the repository at this point in the history
…ge (#4740)

Signed-off-by: terrytangyuan <terrytangyuan@gmail.com>
  • Loading branch information
terrytangyuan authored Dec 18, 2020
1 parent 4ac436d commit 15ec9f5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/example-golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/utils/pointer"

wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
wfclientset "github.com/argoproj/argo/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -60,7 +61,7 @@ func main() {

// wait for the workflow to complete
fieldSelector := fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s", createdWf.Name))
watchIf, err := wfClient.Watch(metav1.ListOptions{FieldSelector: fieldSelector.String()})
watchIf, err := wfClient.Watch(metav1.ListOptions{FieldSelector: fieldSelector.String(), TimeoutSeconds: pointer.Int64Ptr(180)})
errors.CheckError(err)
defer watchIf.Stop()
for next := range watchIf.ResultChan() {
Expand All @@ -69,7 +70,7 @@ func main() {
continue
}
if !wf.Status.FinishedAt.IsZero() {
fmt.Printf("Workflow %s %s at %v\n", wf.Name, wf.Status.Phase, wf.Status.FinishedAt)
fmt.Printf("Workflow %s %s at %v. Message: %s.\n", wf.Name, wf.Status.Phase, wf.Status.FinishedAt, wf.Status.Message)
break
}
}
Expand Down

0 comments on commit 15ec9f5

Please sign in to comment.