Skip to content

Commit f336f5c

Browse files
authored
fix(worker): log before exit error (#5170)
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
1 parent 18c5f78 commit f336f5c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

engine/worker/cmd_run.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67
"os/signal"
78
"syscall"
9+
"time"
810

11+
"github.com/sirupsen/logrus"
912
"github.com/spf13/cobra"
1013

1114
"github.com/ovh/cds/engine/worker/internal"
@@ -62,6 +65,13 @@ func runCmd() func(cmd *cobra.Command, args []string) {
6265
}()
6366
// Start the worker
6467
if err := internal.StartWorker(ctx, w, bookedWJobID); err != nil {
68+
isErrWithStack := sdk.IsErrorWithStack(err)
69+
fields := logrus.Fields{}
70+
if isErrWithStack {
71+
fields["stack_trace"] = fmt.Sprintf("%+v", err)
72+
}
73+
log.ErrorWithFields(ctx, fields, "%v", err)
74+
time.Sleep(2 * time.Second)
6575
sdk.Exit("error: %v", err)
6676
}
6777
}

0 commit comments

Comments
 (0)