@@ -11,6 +11,7 @@ import (
11
11
"errors"
12
12
"fmt"
13
13
"net/http"
14
+ "strings"
14
15
"time"
15
16
16
17
"github.com/avast/retry-go/v4"
@@ -86,10 +87,36 @@ func (c *Client) DeleteTask(ctx context.Context, upid string) error {
86
87
return nil
87
88
}
88
89
90
+ type taskWaitOptions struct {
91
+ ignoreWarnings bool
92
+ }
93
+
94
+ // TaskWaitOption is an option for waiting for a task to complete.
95
+ type TaskWaitOption interface {
96
+ apply (opts * taskWaitOptions )
97
+ }
98
+
99
+ type withIgnoreWarnings struct {}
100
+
101
+ // WithIgnoreWarnings is an option to ignore warnings when waiting for a task to complete.
102
+ func WithIgnoreWarnings () TaskWaitOption {
103
+ return withIgnoreWarnings {}
104
+ }
105
+
106
+ func (w withIgnoreWarnings ) apply (opts * taskWaitOptions ) {
107
+ opts .ignoreWarnings = true
108
+ }
109
+
89
110
// WaitForTask waits for a specific task to complete.
90
- func (c * Client ) WaitForTask (ctx context.Context , upid string ) error {
111
+ func (c * Client ) WaitForTask (ctx context.Context , upid string , opts ... TaskWaitOption ) error {
91
112
errStillRunning := errors .New ("still running" )
92
113
114
+ options := & taskWaitOptions {}
115
+
116
+ for _ , opt := range opts {
117
+ opt .apply (options )
118
+ }
119
+
93
120
status , err := retry .DoWithData (
94
121
func () (* GetTaskStatusResponseData , error ) {
95
122
status , err := c .GetTaskStatus (ctx , upid )
@@ -132,6 +159,11 @@ func (c *Client) WaitForTask(ctx context.Context, upid string) error {
132
159
}
133
160
134
161
if status .ExitCode != "OK" {
162
+ if options .ignoreWarnings &&
163
+ strings .HasPrefix (status .Status , "WARNINGS: " ) && ! strings .Contains (status .Status , "ERROR" ) {
164
+ return nil
165
+ }
166
+
135
167
return fmt .Errorf ("task %q failed to complete with exit code: %s" , upid , status .ExitCode )
136
168
}
137
169
0 commit comments