Skip to content

Commit

Permalink
feat: add data serialization to workflow calls
Browse files Browse the repository at this point in the history
Signed-off-by: mikeee <[email protected]>
  • Loading branch information
mikeee committed Dec 5, 2023
1 parent 4172d0b commit b834f30
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions client/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
Expand All @@ -18,7 +19,7 @@ type StartWorkflowRequest struct {
WorkflowName string
Options map[string]string // Optional metadata
Input []byte // Optional input
// TODO: support data serialization
SendRawInput bool // Set to True in order to disable serialization on the input
}

type StartWorkflowResponse struct {
Expand Down Expand Up @@ -64,10 +65,12 @@ type RaiseEventWorkflowRequest struct {
WorkflowComponent string
EventName string
EventData []byte // Optional data
SendRawData bool // Set to True in order to disable serialization on the data§1
}

// StartWorkflowAlpha1 starts a workflow instance using the alpha1 spec.
func (c *GRPCClient) StartWorkflowAlpha1(ctx context.Context, req *StartWorkflowRequest) (*StartWorkflowResponse, error) {

Check failure on line 72 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.19

unnecessary leading newline (whitespace)

Check failure on line 72 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.20

unnecessary leading newline (whitespace)

Check failure on line 72 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.21

unnecessary leading newline (whitespace)

Check failure on line 73 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.19

File is not `gofumpt`-ed (gofumpt)

Check failure on line 73 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.20

File is not `gofumpt`-ed (gofumpt)

Check failure on line 73 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.21

File is not `gofumpt`-ed (gofumpt)
if req.InstanceID == "" {
req.InstanceID = uuid.New().String()
}
Expand All @@ -78,12 +81,21 @@ func (c *GRPCClient) StartWorkflowAlpha1(ctx context.Context, req *StartWorkflow
if req.WorkflowName == "" {
return nil, errors.New("failed to start workflow: WorkflowName must be supplied")
}

var input = req.Input

Check failure on line 85 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.19

File is not `gofumpt`-ed (gofumpt)

Check failure on line 85 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.20

File is not `gofumpt`-ed (gofumpt)

Check failure on line 85 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.21

File is not `gofumpt`-ed (gofumpt)
var err error
if (!req.SendRawInput) && (input != nil) {
input, err = json.Marshal(input)
if err != nil {
return nil, fmt.Errorf("failed to marshal input: %v", err)
}

Check warning on line 91 in client/workflow.go

View check run for this annotation

Codecov / codecov/patch

client/workflow.go#L88-L91

Added lines #L88 - L91 were not covered by tests
}
resp, err := c.protoClient.StartWorkflowAlpha1(ctx, &pb.StartWorkflowRequest{
InstanceId: req.InstanceID,
WorkflowComponent: req.WorkflowComponent,
WorkflowName: req.WorkflowName,
Options: req.Options,
Input: req.Input,
Input: input,
})
if err != nil {
return nil, fmt.Errorf("failed to start workflow instance: %v", err)
Expand Down Expand Up @@ -208,7 +220,15 @@ func (c *GRPCClient) RaiseEventWorkflowAlpha1(ctx context.Context, req *RaiseEve
if req.EventName == "" {
return errors.New("failed to raise event on workflow: EventName must be supplied")
}
_, err := c.protoClient.RaiseEventWorkflowAlpha1(ctx, &pb.RaiseEventWorkflowRequest{
var input = req.EventData

Check failure on line 223 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.19

File is not `gofumpt`-ed (gofumpt)

Check failure on line 223 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.20

File is not `gofumpt`-ed (gofumpt)

Check failure on line 223 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.21

File is not `gofumpt`-ed (gofumpt)
var err error
if (!req.SendRawData) && (input != nil) {
input, err = json.Marshal(input)

Check failure on line 226 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.19

ineffectual assignment to input (ineffassign)

Check failure on line 226 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.20

ineffectual assignment to input (ineffassign)

Check failure on line 226 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.21

ineffectual assignment to input (ineffassign)
if err != nil {
return fmt.Errorf("failed to marshal input: %v", err)
}

Check warning on line 229 in client/workflow.go

View check run for this annotation

Codecov / codecov/patch

client/workflow.go#L226-L229

Added lines #L226 - L229 were not covered by tests
}
_, err = c.protoClient.RaiseEventWorkflowAlpha1(ctx, &pb.RaiseEventWorkflowRequest{
InstanceId: req.InstanceID,
WorkflowComponent: req.WorkflowComponent,
EventName: req.EventName,
Expand All @@ -231,6 +251,15 @@ func (c *GRPCClient) StartWorkflowBeta1(ctx context.Context, req *StartWorkflowR
if req.WorkflowName == "" {
return nil, errors.New("failed to start workflow: WorkflowName must be supplied")
}

var input = req.Input
var err error
if (!req.SendRawInput) && (req.Input != nil) {
input, err = json.Marshal(input)

Check failure on line 258 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.19

ineffectual assignment to input (ineffassign)

Check failure on line 258 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.20

ineffectual assignment to input (ineffassign)

Check failure on line 258 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.21

ineffectual assignment to input (ineffassign)
if err != nil {
return nil, fmt.Errorf("failed to marshal input: %v", err)
}

Check warning on line 261 in client/workflow.go

View check run for this annotation

Codecov / codecov/patch

client/workflow.go#L258-L261

Added lines #L258 - L261 were not covered by tests
}
resp, err := c.protoClient.StartWorkflowBeta1(ctx, &pb.StartWorkflowRequest{
InstanceId: req.InstanceID,
WorkflowComponent: req.WorkflowComponent,
Expand Down Expand Up @@ -360,7 +389,16 @@ func (c *GRPCClient) RaiseEventWorkflowBeta1(ctx context.Context, req *RaiseEven
if req.EventName == "" {
return errors.New("failed to raise event on workflow: EventName must be supplied")
}
_, err := c.protoClient.RaiseEventWorkflowBeta1(ctx, &pb.RaiseEventWorkflowRequest{

var input = req.EventData
var err error
if (!req.SendRawData) && (input != nil) {
input, err = json.Marshal(input)

Check failure on line 396 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.19

ineffectual assignment to input (ineffassign)

Check failure on line 396 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.20

ineffectual assignment to input (ineffassign)

Check failure on line 396 in client/workflow.go

View workflow job for this annotation

GitHub Actions / Test on 1.21

ineffectual assignment to input (ineffassign)
if err != nil {
return fmt.Errorf("failed to marshal input: %v", err)
}

Check warning on line 399 in client/workflow.go

View check run for this annotation

Codecov / codecov/patch

client/workflow.go#L396-L399

Added lines #L396 - L399 were not covered by tests
}
_, err = c.protoClient.RaiseEventWorkflowBeta1(ctx, &pb.RaiseEventWorkflowRequest{
InstanceId: req.InstanceID,
WorkflowComponent: req.WorkflowComponent,
EventName: req.EventName,
Expand Down

0 comments on commit b834f30

Please sign in to comment.