Skip to content

Commit 75c76e2

Browse files
authored
fix: add retries for getting the execution, increase monitor retries (#6312)
1 parent 26f06dc commit 75c76e2

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

pkg/runner/runner.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ const (
3131
SaveEndResultRetryCount = 100
3232
SaveEndResultRetryBaseDelay = 500 * time.Millisecond
3333

34+
GetExecutionRetryCount = 200
35+
GetExecutionRetryDelay = 500 * time.Millisecond
36+
37+
MonitorRetryCount = 10
38+
MonitorRetryDelay = 500 * time.Millisecond
39+
3440
inlinedGlobalTemplateName = "<inline-global-template>"
3541
)
3642

@@ -227,11 +233,18 @@ func (r *runner) Monitor(ctx context.Context, organizationId string, environment
227233
return nil
228234
}
229235

230-
// Load the execution TODO: retry?
231-
execution, err := r.client.GetExecution(ctx, environmentId, id)
236+
// Load the execution
237+
var execution *testkube.TestWorkflowExecution
238+
err := retry(GetExecutionRetryCount, GetExecutionRetryDelay, func() (err error) {
239+
execution, err = r.client.GetExecution(ctx, environmentId, id)
240+
if err != nil {
241+
log.DefaultLogger.Warnw("failed to get execution for monitoring, retrying...", "id", id, "error", err)
242+
}
243+
return err
244+
})
232245
if err != nil {
233246
r.watching.Delete(id)
234-
log.DefaultLogger.Errorw("failed to get execution", "id", id, "error", err)
247+
log.DefaultLogger.Errorw("failed to get execution for monitoring", "id", id, "error", err)
235248
return err
236249
}
237250

@@ -278,15 +291,16 @@ func (r *runner) execute(request executionworkertypes.ExecuteRequest) (*executio
278291
}
279292
res, err := r.worker.Execute(context.Background(), request)
280293
if err == nil {
281-
// TODO: consider retry?
282294
go func() {
283-
for i := 0; i < 3; i++ {
295+
err := retry(MonitorRetryCount, MonitorRetryDelay, func() error {
284296
err := r.Monitor(context.Background(), request.Execution.OrganizationId, request.Execution.EnvironmentId, request.Execution.Id)
285-
if err == nil {
286-
return
297+
if err != nil {
298+
log.DefaultLogger.Warnw("failed to monitor execution, retrying...", "id", request.Execution.Id, "error", err)
287299
}
300+
return err
301+
})
302+
if err != nil {
288303
log.DefaultLogger.Errorw("failed to monitor execution", "id", request.Execution.Id, "error", err)
289-
time.Sleep(1 * time.Second)
290304
}
291305
}()
292306
}

0 commit comments

Comments
 (0)