Skip to content

Commit d1c1935

Browse files
committed
Documentation
1 parent 9231003 commit d1c1935

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

activitytester/activitytester.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/cschleiden/go-workflows/internal/activity"
99
)
1010

11+
// WithActivityTestState returns a context with an activity state attached that can be used for unit testing
12+
// activities.
1113
func WithActivityTestState(ctx context.Context, activityID, instanceID string, logger *slog.Logger) context.Context {
1214
if logger == nil {
1315
logger = slog.Default()

backend/tasks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/cschleiden/go-workflows/core"
77
)
88

9+
// WorkflowTask represents work for one workflow execution slice.
910
type WorkflowTask struct {
1011
// ID is an identifier for this task. It's set by the backend
1112
ID string
@@ -27,6 +28,7 @@ type WorkflowTask struct {
2728
CustomData any
2829
}
2930

31+
// ActivityTask represents one activity execution.
3032
type ActivityTask struct {
3133
ID string
3234

client/client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func New(backend backend.Backend) *Client {
4242
}
4343
}
4444

45-
func (c *Client) CreateWorkflowInstance(ctx context.Context, options WorkflowInstanceOptions, wf workflow.Workflow, args ...interface{}) (*workflow.Instance, error) {
45+
// CreateWorkflowInstance creates a new workflow instance of the given workflow.
46+
func (c *Client) CreateWorkflowInstance(ctx context.Context, options WorkflowInstanceOptions, wf workflow.Workflow, args ...any) (*workflow.Instance, error) {
4647
// Check arguments
4748
if err := a.ParamsMatch(wf, args...); err != nil {
4849
return nil, err
@@ -89,6 +90,7 @@ func (c *Client) CreateWorkflowInstance(ctx context.Context, options WorkflowIns
8990
return wfi, nil
9091
}
9192

93+
// CancelWorkflowInstance cancels a running workflow instance.
9294
func (c *Client) CancelWorkflowInstance(ctx context.Context, instance *workflow.Instance) error {
9395
ctx, span := c.backend.Tracer().Start(ctx, "CancelWorkflowInstance", trace.WithAttributes(
9496
attribute.String(log.InstanceIDKey, instance.InstanceID),
@@ -99,7 +101,8 @@ func (c *Client) CancelWorkflowInstance(ctx context.Context, instance *workflow.
99101
return c.backend.CancelWorkflowInstance(ctx, instance, cancellationEvent)
100102
}
101103

102-
func (c *Client) SignalWorkflow(ctx context.Context, instanceID string, name string, arg interface{}) error {
104+
// SignalWorkflow signals a running workflow instance.
105+
func (c *Client) SignalWorkflow(ctx context.Context, instanceID string, name string, arg any) error {
103106
ctx, span := c.backend.Tracer().Start(ctx, "SignalWorkflow", trace.WithAttributes(
104107
attribute.String(log.InstanceIDKey, instanceID),
105108
attribute.String(log.SignalNameKey, name),
@@ -131,6 +134,7 @@ func (c *Client) SignalWorkflow(ctx context.Context, instanceID string, name str
131134
return nil
132135
}
133136

137+
// WaitForWorkflowInstance waits for the given workflow instance to finish or until the given timeout has expired.
134138
func (c *Client) WaitForWorkflowInstance(ctx context.Context, instance *workflow.Instance, timeout time.Duration) error {
135139
if timeout == 0 {
136140
timeout = time.Second * 20
@@ -226,6 +230,7 @@ func GetWorkflowResult[T any](ctx context.Context, c *Client, instance *workflow
226230
return *new(T), errors.New("workflow finished, but could not find result event")
227231
}
228232

233+
// RemoveWorkflowInstance removes the given workflow instance from the backend.
229234
func (c *Client) RemoveWorkflowInstance(ctx context.Context, instance *core.WorkflowInstance) error {
230235
ctx, span := c.backend.Tracer().Start(ctx, "RemoveWorkflowInstance", trace.WithAttributes(
231236
attribute.String(log.InstanceIDKey, instance.InstanceID),

client/stats.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/cschleiden/go-workflows/backend"
77
)
88

9+
// GetStats returns backend stats.
910
func (c *Client) GetStats(ctx context.Context) (*backend.Stats, error) {
1011
return c.backend.GetStats(ctx)
1112
}

core/instance.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package core
22

33
type WorkflowInstance struct {
4-
InstanceID string `json:"instance_id,omitempty"`
4+
// InstanceID is the ID of the workflow instance.
5+
InstanceID string `json:"instance_id,omitempty"`
6+
7+
// ExecutionID is the ID of the current execution of the workflow instance.
58
ExecutionID string `json:"execution_id,omitempty"`
69

7-
Parent *WorkflowInstance `json:"parent,omitempty"`
8-
ParentEventID int64 `json:"parent_event_id,omitempty"`
10+
// Parent refers to the parent workflow instance if this instance is a sub-workflow.
11+
Parent *WorkflowInstance `json:"parent,omitempty"`
12+
13+
// ParentEventID is the ID of the event in the parent workflow that started this sub-workflow.
14+
ParentEventID int64 `json:"parent_event_id,omitempty"`
915
}
1016

1117
func NewWorkflowInstance(instanceID, executionID string) *WorkflowInstance {

tester/tester.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@ func (wt *workflowTester[TResult]) ListenSubWorkflow(listener func(*core.Workflo
250250
wt.subWorkflowListener = listener
251251
}
252252

253-
func (wt *workflowTester[TResult]) OnActivityByName(name string, activity workflow.Activity, args ...interface{}) *mock.Call {
253+
func (wt *workflowTester[TResult]) OnActivityByName(name string, activity workflow.Activity, args ...any) *mock.Call {
254254
// Register activity so that we can correctly identify its arguments later
255255
wt.registry.RegisterActivityByName(name, activity)
256256

257257
wt.mockedActivities[name] = true
258258
return wt.ma.On(name, args...)
259259
}
260260

261-
func (wt *workflowTester[TResult]) OnActivity(activity workflow.Activity, args ...interface{}) *mock.Call {
261+
func (wt *workflowTester[TResult]) OnActivity(activity workflow.Activity, args ...any) *mock.Call {
262262
// Register activity so that we can correctly identify its arguments later
263263
wt.registry.RegisterActivity(activity)
264264

@@ -267,15 +267,15 @@ func (wt *workflowTester[TResult]) OnActivity(activity workflow.Activity, args .
267267
return wt.ma.On(name, args...)
268268
}
269269

270-
func (wt *workflowTester[TResult]) OnSubWorkflowByName(name string, workflow workflow.Workflow, args ...interface{}) *mock.Call {
270+
func (wt *workflowTester[TResult]) OnSubWorkflowByName(name string, workflow workflow.Workflow, args ...any) *mock.Call {
271271
// Register workflow so that we can correctly identify its arguments later
272272
wt.registry.RegisterWorkflowByName(name, workflow)
273273

274274
wt.mockedWorkflows[name] = true
275275
return wt.mw.On(name, args...)
276276
}
277277

278-
func (wt *workflowTester[TResult]) OnSubWorkflow(workflow workflow.Workflow, args ...interface{}) *mock.Call {
278+
func (wt *workflowTester[TResult]) OnSubWorkflow(workflow workflow.Workflow, args ...any) *mock.Call {
279279
// Register workflow so that we can correctly identify its arguments later
280280
wt.registry.RegisterWorkflow(workflow)
281281

@@ -284,7 +284,7 @@ func (wt *workflowTester[TResult]) OnSubWorkflow(workflow workflow.Workflow, arg
284284
return wt.mw.On(name, args...)
285285
}
286286

287-
func (wt *workflowTester[TResult]) Execute(ctx context.Context, args ...interface{}) {
287+
func (wt *workflowTester[TResult]) Execute(ctx context.Context, args ...any) {
288288
for _, propagator := range wt.propagators {
289289
if err := propagator.Inject(ctx, wt.wfm); err != nil {
290290
panic(fmt.Errorf("failed to inject context: %w", err))

0 commit comments

Comments
 (0)