Skip to content

Commit

Permalink
make workflow client struct public (dapr#577)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Martinez <[email protected]>
  • Loading branch information
famarting authored Jul 10, 2024
1 parent d3eef2e commit a1e723b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions workflow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
dapr "github.com/dapr/go-sdk/client"
)

type client struct {
type Client struct {
taskHubClient *durabletaskclient.TaskHubGrpcClient
}

Expand Down Expand Up @@ -95,11 +95,11 @@ func WithDaprClient(input dapr.Client) clientOption {
// TODO: Implement mocks

// NewClient returns a workflow client.
func NewClient(opts ...clientOption) (client, error) {
func NewClient(opts ...clientOption) (*Client, error) {
options := new(clientOptions)
for _, configure := range opts {
if err := configure(options); err != nil {
return client{}, fmt.Errorf("failed to load options: %v", err)
return &Client{}, fmt.Errorf("failed to load options: %v", err)
}
}
var daprClient dapr.Client
Expand All @@ -110,18 +110,18 @@ func NewClient(opts ...clientOption) (client, error) {
daprClient = options.daprClient
}
if err != nil {
return client{}, fmt.Errorf("failed to initialise dapr.Client: %v", err)
return &Client{}, fmt.Errorf("failed to initialise dapr.Client: %v", err)
}

taskHubClient := durabletaskclient.NewTaskHubGrpcClient(daprClient.GrpcClientConn(), backend.DefaultLogger())

return client{
return &Client{
taskHubClient: taskHubClient,
}, nil
}

// ScheduleNewWorkflow will start a workflow and return the ID and/or error.
func (c *client) ScheduleNewWorkflow(ctx context.Context, workflow string, opts ...api.NewOrchestrationOptions) (id string, err error) {
func (c *Client) ScheduleNewWorkflow(ctx context.Context, workflow string, opts ...api.NewOrchestrationOptions) (id string, err error) {
if workflow == "" {
return "", errors.New("no workflow specified")
}
Expand All @@ -130,7 +130,7 @@ func (c *client) ScheduleNewWorkflow(ctx context.Context, workflow string, opts
}

// FetchWorkflowMetadata will return the metadata for a given workflow InstanceID and/or error.
func (c *client) FetchWorkflowMetadata(ctx context.Context, id string, opts ...api.FetchOrchestrationMetadataOptions) (*Metadata, error) {
func (c *Client) FetchWorkflowMetadata(ctx context.Context, id string, opts ...api.FetchOrchestrationMetadataOptions) (*Metadata, error) {
if id == "" {
return nil, errors.New("no workflow id specified")
}
Expand All @@ -143,7 +143,7 @@ func (c *client) FetchWorkflowMetadata(ctx context.Context, id string, opts ...a
}

// WaitForWorkflowStart will wait for a given workflow to start and return metadata and/or an error.
func (c *client) WaitForWorkflowStart(ctx context.Context, id string, opts ...api.FetchOrchestrationMetadataOptions) (*Metadata, error) {
func (c *Client) WaitForWorkflowStart(ctx context.Context, id string, opts ...api.FetchOrchestrationMetadataOptions) (*Metadata, error) {
if id == "" {
return nil, errors.New("no workflow id specified")
}
Expand All @@ -156,7 +156,7 @@ func (c *client) WaitForWorkflowStart(ctx context.Context, id string, opts ...ap
}

// WaitForWorkflowCompletion will block pending the completion of a specified workflow and return the metadata and/or error.
func (c *client) WaitForWorkflowCompletion(ctx context.Context, id string, opts ...api.FetchOrchestrationMetadataOptions) (*Metadata, error) {
func (c *Client) WaitForWorkflowCompletion(ctx context.Context, id string, opts ...api.FetchOrchestrationMetadataOptions) (*Metadata, error) {
if id == "" {
return nil, errors.New("no workflow id specified")
}
Expand All @@ -169,15 +169,15 @@ func (c *client) WaitForWorkflowCompletion(ctx context.Context, id string, opts
}

// TerminateWorkflow will stop a given workflow and return an error output.
func (c *client) TerminateWorkflow(ctx context.Context, id string, opts ...api.TerminateOptions) error {
func (c *Client) TerminateWorkflow(ctx context.Context, id string, opts ...api.TerminateOptions) error {
if id == "" {
return errors.New("no workflow id specified")
}
return c.taskHubClient.TerminateOrchestration(ctx, api.InstanceID(id), opts...)
}

// RaiseEvent will raise an event on a given workflow and return an error output.
func (c *client) RaiseEvent(ctx context.Context, id, eventName string, opts ...api.RaiseEventOptions) error {
func (c *Client) RaiseEvent(ctx context.Context, id, eventName string, opts ...api.RaiseEventOptions) error {
if id == "" {
return errors.New("no workflow id specified")
}
Expand All @@ -188,15 +188,15 @@ func (c *client) RaiseEvent(ctx context.Context, id, eventName string, opts ...a
}

// SuspendWorkflow will pause a given workflow and return an error output.
func (c *client) SuspendWorkflow(ctx context.Context, id, reason string) error {
func (c *Client) SuspendWorkflow(ctx context.Context, id, reason string) error {
if id == "" {
return errors.New("no workflow id specified")
}
return c.taskHubClient.SuspendOrchestration(ctx, api.InstanceID(id), reason)
}

// ResumeWorkflow will resume a suspended workflow and return an error output.
func (c *client) ResumeWorkflow(ctx context.Context, id, reason string) error {
func (c *Client) ResumeWorkflow(ctx context.Context, id, reason string) error {
if id == "" {
return errors.New("no workflow id specified")
}
Expand All @@ -205,7 +205,7 @@ func (c *client) ResumeWorkflow(ctx context.Context, id, reason string) error {

// PurgeWorkflow will purge a given workflow and return an error output.
// NOTE: The workflow must be in a terminated or completed state.
func (c *client) PurgeWorkflow(ctx context.Context, id string) error {
func (c *Client) PurgeWorkflow(ctx context.Context, id string) error {
if id == "" {
return errors.New("no workflow id specified")
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func returnClientOptions(opts ...clientOption) clientOptions {
}

func TestClientMethods(t *testing.T) {
testClient := client{
testClient := Client{
taskHubClient: nil,
}
ctx := context.Background()
Expand Down

0 comments on commit a1e723b

Please sign in to comment.