Skip to content

Commit

Permalink
merge: #9417
Browse files Browse the repository at this point in the history
9417: feat(client-go): add support for backoff timeout for failed jobs in the Go client and zbctl r=pihme a=aivinog1

## Description

<!-- Please explain the changes you made here. -->
I've added mapping in the Go client and an additional flag that matches job backoff.

## Related issues

<!-- Which issues are closed by this PR or are related -->

closes #5629 



Co-authored-by: Alexey Vinogradov <vinogradov.a.i.93@gmail.com>
  • Loading branch information
zeebe-bors-camunda[bot] and aivinog1 committed Jun 1, 2022
2 parents 5432430 + 8d6ce5d commit 4dcf344
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
12 changes: 8 additions & 4 deletions clients/go/cmd/zbctl/internal/commands/failJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@ import (
"github.com/camunda/zeebe/clients/go/v8/pkg/commands"
"github.com/camunda/zeebe/clients/go/v8/pkg/pb"
"github.com/spf13/cobra"
"time"
)

type FailJobResponseWrapper struct {
resp *pb.FailJobResponse
}

func (f FailJobResponseWrapper) human() (string, error) {
return fmt.Sprint("Failed job with key '", failJobKey, "' and set remaining retries to '", failJobRetriesFlag, "'"), nil
return fmt.Sprint("Failed job with key '", failJobKey, "' and set remaining retries to '", failJobRetriesFlag, "' with retry backoff '", failJobRetryBackoffFlag, "'"), nil
}

func (f FailJobResponseWrapper) json() (string, error) {
return toJSON(f.resp)
}

var (
failJobKey int64
failJobRetriesFlag int32
failJobErrorMessage string
failJobKey int64
failJobRetriesFlag int32
failJobRetryBackoffFlag time.Duration
failJobErrorMessage string
)

var failJobCmd = &cobra.Command{
Expand All @@ -52,6 +54,7 @@ var failJobCmd = &cobra.Command{
resp, err := client.NewFailJobCommand().
JobKey(failJobKey).
Retries(failJobRetriesFlag).
RetryBackoff(failJobRetryBackoffFlag).
ErrorMessage(failJobErrorMessage).
Send(ctx)
if err != nil {
Expand All @@ -69,6 +72,7 @@ func init() {
if err := failJobCmd.MarkFlagRequired("retries"); err != nil {
panic(err)
}
failJobCmd.Flags().DurationVar(&failJobRetryBackoffFlag, "retryBackoff", time.Second*0, "Specify retry backoff of job. Example values: 300ms, 50s or 1m")

failJobCmd.Flags().StringVar(&failJobErrorMessage, "errorMessage", "", "Specify failure error message")

Expand Down
7 changes: 7 additions & 0 deletions clients/go/pkg/commands/fail_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package commands
import (
"context"
"github.com/camunda/zeebe/clients/go/v8/pkg/pb"
"time"
)

type DispatchFailJobCommand interface {
Expand All @@ -34,6 +35,7 @@ type FailJobCommandStep2 interface {

type FailJobCommandStep3 interface {
DispatchFailJobCommand
RetryBackoff(retryBackoff time.Duration) FailJobCommandStep3
ErrorMessage(string) FailJobCommandStep3
}

Expand All @@ -52,6 +54,11 @@ func (cmd *FailJobCommand) Retries(retries int32) FailJobCommandStep3 {
return cmd
}

func (cmd *FailJobCommand) RetryBackoff(retryBackoff time.Duration) FailJobCommandStep3 {
cmd.request.RetryBackOff = retryBackoff.Milliseconds()
return cmd
}

func (cmd *FailJobCommand) ErrorMessage(errorMessage string) FailJobCommandStep3 {
cmd.request.ErrorMessage = errorMessage
return cmd
Expand Down
31 changes: 31 additions & 0 deletions clients/go/pkg/commands/fail_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/camunda/zeebe/clients/go/v8/pkg/pb"
"github.com/golang/mock/gomock"
"testing"
"time"
)

func TestFailJobCommand(t *testing.T) {
Expand Down Expand Up @@ -53,6 +54,36 @@ func TestFailJobCommand(t *testing.T) {
t.Errorf("Failed to receive response")
}
}
func TestFailJobCommand_RetryBackoff(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := mock_pb.NewMockGatewayClient(ctrl)

request := &pb.FailJobRequest{
JobKey: 123,
Retries: 12,
RetryBackOff: 10_000,
}
stub := &pb.FailJobResponse{}

client.EXPECT().FailJob(gomock.Any(), &utils.RPCTestMsg{Msg: request}).Return(stub, nil)

command := NewFailJobCommand(client, func(context.Context, error) bool { return false })

ctx, cancel := context.WithTimeout(context.Background(), utils.DefaultTestTimeout)
defer cancel()

response, err := command.JobKey(123).Retries(12).RetryBackoff(time.Second * 10).Send(ctx)

if err != nil {
t.Errorf("Failed to send request")
}

if response != stub {
t.Errorf("Failed to receive response")
}
}

func TestFailJobCommand_ErrorMessage(t *testing.T) {
ctrl := gomock.NewController(t)
Expand Down

0 comments on commit 4dcf344

Please sign in to comment.