Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow grpc start API: Generate instanceID if not present #7503

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 0 additions & 10 deletions pkg/api/http/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strconv"

"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/dapr/dapr/pkg/api/http/endpoints"
Expand Down Expand Up @@ -201,16 +200,7 @@ func (a *api) onStartWorkflowHandler() http.HandlerFunc {
InModifier: func(r *http.Request, in *runtimev1pb.StartWorkflowRequest) (*runtimev1pb.StartWorkflowRequest, error) {
in.WorkflowName = chi.URLParam(r, workflowName)
in.WorkflowComponent = chi.URLParam(r, workflowComponent)

// The instance ID is optional. If not specified, we generate a random one.
in.InstanceId = r.URL.Query().Get(instanceID)
if in.GetInstanceId() == "" {
randomID, err := uuid.NewRandom()
if err != nil {
return nil, err
}
in.InstanceId = randomID.String()
}

// We accept the HTTP request body as the input to the workflow
// without making any assumptions about its format.
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/universal/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"errors"
"unicode"

"github.com/google/uuid"
"github.com/microsoft/durabletask-go/api"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -69,6 +70,14 @@

// StartWorkflowBeta1 is the API handler for starting a workflow
func (a *Universal) StartWorkflowBeta1(ctx context.Context, in *runtimev1pb.StartWorkflowRequest) (*runtimev1pb.StartWorkflowResponse, error) {
// The instance ID is optional. If not specified, we generate a random one.
if in.GetInstanceId() == "" {
randomID, err := uuid.NewRandom()
if err != nil {
return nil, err

Check warning on line 77 in pkg/api/universal/workflow.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/universal/workflow.go#L77

Added line #L77 was not covered by tests
}
in.InstanceId = randomID.String()
}
if err := a.validateInstanceID(in.GetInstanceId(), true /* isCreate */); err != nil {
a.logger.Debug(err)
return &runtimev1pb.StartWorkflowResponse{}, err
Expand Down
13 changes: 6 additions & 7 deletions pkg/api/universal/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ func TestStartWorkflowBeta1API(t *testing.T) {
instanceID: fakeInstanceID,
expectedError: messages.ErrWorkflowNameMissing,
},
{
testName: "No instance ID provided in start request",
workflowComponent: fakeComponentName,
workflowName: fakeWorkflowName,
instanceID: "",
expectedError: messages.ErrMissingOrEmptyInstance,
},
{
testName: "Invalid instance ID provided in start request",
workflowComponent: fakeComponentName,
Expand All @@ -98,6 +91,12 @@ func TestStartWorkflowBeta1API(t *testing.T) {
instanceID: daprt.ErrorInstanceID,
expectedError: messages.ErrStartWorkflow.WithFormat(fakeWorkflowName, daprt.ErrFakeWorkflowComponentError),
},
{
testName: "No instance ID provided in start request",
workflowComponent: fakeComponentName,
workflowName: fakeWorkflowName,
instanceID: "",
},
{
testName: "All is well in start request",
workflowComponent: fakeComponentName,
Expand Down