Skip to content

Commit e1c0cca

Browse files
committed
Added StartWorkflowWithContext to executor
1 parent 0346190 commit e1c0cca

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

sdk/workflow/executor/executor.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,16 @@ func (e *WorkflowExecutor) MonitorExecution(workflowId string) (workflowMonitor
131131
// StartWorkflow Start workflows
132132
// Returns the id of the newly created workflow
133133
func (e *WorkflowExecutor) StartWorkflow(startWorkflowRequest *model.StartWorkflowRequest) (workflowId string, err error) {
134+
return e.StartWorkflowWithContext(context.Background(), startWorkflowRequest)
135+
}
136+
137+
func (e *WorkflowExecutor) StartWorkflowWithContext(ctx context.Context, startWorkflowRequest *model.StartWorkflowRequest) (workflowId string, err error) {
138+
if err := ctx.Err(); err != nil {
139+
return "", err
140+
}
141+
134142
id, _, err := e.workflowClient.StartWorkflowWithRequest(
135-
context.Background(),
143+
ctx,
136144
*startWorkflowRequest,
137145
)
138146
if err != nil {

test/integration_tests/executor_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package integration_tests
22

33
import (
4+
"context"
45
"fmt"
5-
"testing"
6-
76
"github.com/conductor-sdk/conductor-go/sdk/client"
87
"github.com/conductor-sdk/conductor-go/sdk/model"
98
"github.com/conductor-sdk/conductor-go/sdk/workflow"
109
"github.com/conductor-sdk/conductor-go/test/testdata"
1110
"github.com/stretchr/testify/assert"
11+
"testing"
1212
)
1313

1414
const (
@@ -90,3 +90,14 @@ func TestUpdate(t *testing.T) {
9090
assert.Fail(t, "err is not of type GenericSwaggerError")
9191
}
9292
}
93+
94+
func TestStartWorkflowWithContext(t *testing.T) {
95+
executor := testdata.WorkflowExecutor
96+
97+
ctx, cancel := context.WithCancel(context.Background())
98+
cancel()
99+
100+
_, err := executor.StartWorkflowWithContext(ctx, &model.StartWorkflowRequest{})
101+
assert.Error(t, err, "StartWorkflowWithContext is expected to return an error")
102+
assert.Equal(t, context.Canceled, err, "Expected context canceled error")
103+
}

0 commit comments

Comments
 (0)