Skip to content

Commit a66dc96

Browse files
authored
HMS-5127: force task requeue on server exit (#934)
1 parent f3dc32a commit a66dc96

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/tasks/worker/worker.go

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/content-services/content-sources-backend/pkg/config"
11+
ce "github.com/content-services/content-sources-backend/pkg/errors"
1112
m "github.com/content-services/content-sources-backend/pkg/instrumentation"
1213
"github.com/content-services/content-sources-backend/pkg/models"
1314
"github.com/content-services/content-sources-backend/pkg/tasks"
@@ -175,6 +176,14 @@ func (w *worker) process(ctx context.Context, taskInfo *models.TaskInfo) {
175176

176177
handlerErr := handler(ctx, taskInfo, &w.queue)
177178

179+
// Exit early if the server exits to allow the task to requeue. Finish is not needed.
180+
// We do not want to clear the running task, mark the worker as ready, or record a message result
181+
// because we expect the task to requeue and the worker to exit
182+
if errors.Is(handlerErr, ce.ErrServerExited) {
183+
w.runningTask.taskCancelFunc(queue.ErrNotRunning)
184+
return
185+
}
186+
178187
// Exit early if the task is canceled. Finish is not needed.
179188
// During a db transaction, a canceled Context doesn't always result in a proper error
180189
// We can check for ErrTxDone in that case: https://github.com/golang/go/issues/43507

0 commit comments

Comments
 (0)