Skip to content

Commit

Permalink
Added StartWorkflowWithContext to executor
Browse files Browse the repository at this point in the history
  • Loading branch information
jmigueprieto committed Nov 7, 2024
1 parent 0346190 commit e1c0cca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 9 additions & 1 deletion sdk/workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ func (e *WorkflowExecutor) MonitorExecution(workflowId string) (workflowMonitor
// StartWorkflow Start workflows
// Returns the id of the newly created workflow
func (e *WorkflowExecutor) StartWorkflow(startWorkflowRequest *model.StartWorkflowRequest) (workflowId string, err error) {
return e.StartWorkflowWithContext(context.Background(), startWorkflowRequest)
}

func (e *WorkflowExecutor) StartWorkflowWithContext(ctx context.Context, startWorkflowRequest *model.StartWorkflowRequest) (workflowId string, err error) {
if err := ctx.Err(); err != nil {
return "", err
}

id, _, err := e.workflowClient.StartWorkflowWithRequest(
context.Background(),
ctx,
*startWorkflowRequest,
)
if err != nil {
Expand Down
15 changes: 13 additions & 2 deletions test/integration_tests/executor_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package integration_tests

import (
"context"
"fmt"
"testing"

"github.com/conductor-sdk/conductor-go/sdk/client"
"github.com/conductor-sdk/conductor-go/sdk/model"
"github.com/conductor-sdk/conductor-go/sdk/workflow"
"github.com/conductor-sdk/conductor-go/test/testdata"
"github.com/stretchr/testify/assert"
"testing"
)

const (
Expand Down Expand Up @@ -90,3 +90,14 @@ func TestUpdate(t *testing.T) {
assert.Fail(t, "err is not of type GenericSwaggerError")
}
}

func TestStartWorkflowWithContext(t *testing.T) {
executor := testdata.WorkflowExecutor

ctx, cancel := context.WithCancel(context.Background())
cancel()

_, err := executor.StartWorkflowWithContext(ctx, &model.StartWorkflowRequest{})
assert.Error(t, err, "StartWorkflowWithContext is expected to return an error")
assert.Equal(t, context.Canceled, err, "Expected context canceled error")
}

0 comments on commit e1c0cca

Please sign in to comment.