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

make workflow client struct public #577

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
dapr "github.com/dapr/go-sdk/client"
)

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

Expand Down Expand Up @@ -95,11 +95,11 @@
// 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)

Check warning on line 102 in workflow/client.go

View check run for this annotation

Codecov / codecov/patch

workflow/client.go#L102

Added line #L102 was not covered by tests
}
}
var daprClient dapr.Client
Expand All @@ -110,18 +110,18 @@
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{

Check warning on line 118 in workflow/client.go

View check run for this annotation

Codecov / codecov/patch

workflow/client.go#L118

Added line #L118 was not covered by tests
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 @@
}

// 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 @@ -140,7 +140,7 @@
}

// 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 @@ -150,7 +150,7 @@
}

// 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 @@ -160,15 +160,15 @@
}

// 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 @@ -179,15 +179,15 @@
}

// 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 @@ -196,7 +196,7 @@

// 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
Loading