Skip to content

Commit 47a57ae

Browse files
committed
Update wf instance references
1 parent 631f090 commit 47a57ae

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

backend/backend.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package backend
33
import (
44
"context"
55

6-
"github.com/cschleiden/go-workflows/internal/core"
76
"github.com/cschleiden/go-workflows/internal/history"
87
"github.com/cschleiden/go-workflows/internal/task"
8+
"github.com/cschleiden/go-workflows/workflow"
99
)
1010

1111
//go:generate mockery --name=Backend --inpackage
@@ -14,7 +14,7 @@ type Backend interface {
1414
CreateWorkflowInstance(ctx context.Context, event history.WorkflowEvent) error
1515

1616
// CancelWorkflowInstance cancels a running workflow instance
17-
CancelWorkflowInstance(ctx context.Context, instance core.WorkflowInstance) error
17+
CancelWorkflowInstance(ctx context.Context, instance workflow.Instance) error
1818

1919
// SignalWorkflow signals a running workflow instance
2020
SignalWorkflow(ctx context.Context, instanceID string, event history.Event) error
@@ -23,20 +23,20 @@ type Backend interface {
2323
GetWorkflowTask(ctx context.Context) (*task.Workflow, error)
2424

2525
// ExtendWorkflowTask extends the lock of a workflow task
26-
ExtendWorkflowTask(ctx context.Context, instance core.WorkflowInstance) error
26+
ExtendWorkflowTask(ctx context.Context, instance workflow.Instance) error
2727

2828
// CompleteWorkflowTask checkpoints a workflow task retrieved using GetWorkflowTask
2929
//
3030
// This checkpoints the execution. events are new events from the last workflow execution
3131
// which will be added to the workflow instance history. workflowEvents are new events for the
3232
// completed or other workflow instances.
33-
CompleteWorkflowTask(ctx context.Context, instance core.WorkflowInstance, executedEvents []history.Event, workflowEvents []history.WorkflowEvent) error
33+
CompleteWorkflowTask(ctx context.Context, instance workflow.Instance, executedEvents []history.Event, workflowEvents []history.WorkflowEvent) error
3434

3535
// GetActivityTask returns a pending activity task or nil if there are no pending activities
3636
GetActivityTask(ctx context.Context) (*task.Activity, error)
3737

3838
// CompleteActivityTask completes a activity task retrieved using GetActivityTask
39-
CompleteActivityTask(ctx context.Context, instance core.WorkflowInstance, activityID string, event history.Event) error
39+
CompleteActivityTask(ctx context.Context, instance workflow.Instance, activityID string, event history.Event) error
4040

4141
// ExtendActivityTask extends the lock of an activity task
4242
ExtendActivityTask(ctx context.Context, activityID string) error

backend/mysql/mysql.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/cschleiden/go-workflows/internal/core"
1313
"github.com/cschleiden/go-workflows/internal/history"
1414
"github.com/cschleiden/go-workflows/internal/task"
15+
"github.com/cschleiden/go-workflows/workflow"
1516
_ "github.com/go-sql-driver/mysql"
1617
"github.com/google/uuid"
1718
"github.com/pkg/errors"
@@ -80,7 +81,7 @@ func (b *mysqlBackend) CreateWorkflowInstance(ctx context.Context, m history.Wor
8081
return nil
8182
}
8283

83-
func (b *mysqlBackend) CancelWorkflowInstance(ctx context.Context, instance core.WorkflowInstance) error {
84+
func (b *mysqlBackend) CancelWorkflowInstance(ctx context.Context, instance workflow.Instance) error {
8485
tx, err := b.db.BeginTx(ctx, nil)
8586
if err != nil {
8687
return err
@@ -119,7 +120,7 @@ func (b *mysqlBackend) CancelWorkflowInstance(ctx context.Context, instance core
119120
return tx.Commit()
120121
}
121122

122-
func createInstance(ctx context.Context, tx *sql.Tx, wfi core.WorkflowInstance) error {
123+
func createInstance(ctx context.Context, tx *sql.Tx, wfi workflow.Instance) error {
123124
var parentInstanceID *string
124125
var parentEventID *int
125126
if wfi.SubWorkflow() {
@@ -225,7 +226,7 @@ func (b *mysqlBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, err
225226
kind = task.Continuation
226227
}
227228

228-
var wfi core.WorkflowInstance
229+
var wfi workflow.Instance
229230
if parentInstanceID != nil {
230231
wfi = core.NewSubWorkflowInstance(instanceID, executionID, core.NewWorkflowInstance(*parentInstanceID, ""), *parentEventID)
231232
} else {
@@ -358,7 +359,7 @@ func (b *mysqlBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, err
358359
// completed or other workflow instances.
359360
func (b *mysqlBackend) CompleteWorkflowTask(
360361
ctx context.Context,
361-
instance core.WorkflowInstance,
362+
instance workflow.Instance,
362363
executedEvents []history.Event,
363364
workflowEvents []history.WorkflowEvent,
364365
) error {
@@ -428,7 +429,7 @@ func (b *mysqlBackend) CompleteWorkflowTask(
428429
}
429430

430431
// Insert new workflow events
431-
groupedEvents := make(map[core.WorkflowInstance][]history.Event)
432+
groupedEvents := make(map[workflow.Instance][]history.Event)
432433
for _, m := range workflowEvents {
433434
if _, ok := groupedEvents[m.WorkflowInstance]; !ok {
434435
groupedEvents[m.WorkflowInstance] = []history.Event{}
@@ -469,7 +470,7 @@ func (b *mysqlBackend) CompleteWorkflowTask(
469470
return nil
470471
}
471472

472-
func (b *mysqlBackend) ExtendWorkflowTask(ctx context.Context, instance core.WorkflowInstance) error {
473+
func (b *mysqlBackend) ExtendWorkflowTask(ctx context.Context, instance workflow.Instance) error {
473474
tx, err := b.db.BeginTx(ctx, nil)
474475
if err != nil {
475476
return err
@@ -562,7 +563,7 @@ func (b *mysqlBackend) GetActivityTask(ctx context.Context) (*task.Activity, err
562563
}
563564

564565
// CompleteActivityTask completes a activity task retrieved using GetActivityTask
565-
func (b *mysqlBackend) CompleteActivityTask(ctx context.Context, instance core.WorkflowInstance, id string, event history.Event) error {
566+
func (b *mysqlBackend) CompleteActivityTask(ctx context.Context, instance workflow.Instance, id string, event history.Event) error {
566567
tx, err := b.db.BeginTx(ctx, nil)
567568
if err != nil {
568569
return err

backend/sqlite/sqlite.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/cschleiden/go-workflows/internal/core"
1313
"github.com/cschleiden/go-workflows/internal/history"
1414
"github.com/cschleiden/go-workflows/internal/task"
15+
"github.com/cschleiden/go-workflows/workflow"
1516
"github.com/google/uuid"
1617
"github.com/pkg/errors"
1718

@@ -81,7 +82,7 @@ func (sb *sqliteBackend) CreateWorkflowInstance(ctx context.Context, m history.W
8182
return nil
8283
}
8384

84-
func createInstance(ctx context.Context, tx *sql.Tx, wfi core.WorkflowInstance) error {
85+
func createInstance(ctx context.Context, tx *sql.Tx, wfi workflow.Instance) error {
8586
var parentInstanceID *string
8687
var parentEventID *int
8788
if wfi.SubWorkflow() {
@@ -106,7 +107,7 @@ func createInstance(ctx context.Context, tx *sql.Tx, wfi core.WorkflowInstance)
106107
return nil
107108
}
108109

109-
func (sb *sqliteBackend) CancelWorkflowInstance(ctx context.Context, instance core.WorkflowInstance) error {
110+
func (sb *sqliteBackend) CancelWorkflowInstance(ctx context.Context, instance workflow.Instance) error {
110111
tx, err := sb.db.BeginTx(ctx, nil)
111112
if err != nil {
112113
return err
@@ -212,7 +213,7 @@ func (sb *sqliteBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, e
212213
kind = task.Continuation
213214
}
214215

215-
var wfi core.WorkflowInstance
216+
var wfi workflow.Instance
216217
if parentInstanceID != nil {
217218
wfi = core.NewSubWorkflowInstance(instanceID, executionID, core.NewWorkflowInstance(*parentInstanceID, ""), *parentEventID)
218219
} else {
@@ -267,11 +268,11 @@ func (sb *sqliteBackend) GetWorkflowTask(ctx context.Context) (*task.Workflow, e
267268
return t, nil
268269
}
269270

270-
// CompleteWorkflowTask(ctx context.Context, instance core.WorkflowInstance, executedEvents []history.Event, workflowEvents []history.WorkflowEvent) error
271+
// CompleteWorkflowTask(ctx context.Context, instance workflow.Instance, executedEvents []history.Event, workflowEvents []history.WorkflowEvent) error
271272

272273
func (sb *sqliteBackend) CompleteWorkflowTask(
273274
ctx context.Context,
274-
instance core.WorkflowInstance,
275+
instance workflow.Instance,
275276
executedEvents []history.Event,
276277
workflowEvents []history.WorkflowEvent,
277278
) error {
@@ -335,7 +336,7 @@ func (sb *sqliteBackend) CompleteWorkflowTask(
335336
}
336337

337338
// Insert new workflow events
338-
groupedEvents := make(map[core.WorkflowInstance][]history.Event)
339+
groupedEvents := make(map[workflow.Instance][]history.Event)
339340
for _, m := range workflowEvents {
340341
if _, ok := groupedEvents[m.WorkflowInstance]; !ok {
341342
groupedEvents[m.WorkflowInstance] = []history.Event{}
@@ -373,7 +374,7 @@ func (sb *sqliteBackend) CompleteWorkflowTask(
373374
return tx.Commit()
374375
}
375376

376-
func (sb *sqliteBackend) ExtendWorkflowTask(ctx context.Context, instance core.WorkflowInstance) error {
377+
func (sb *sqliteBackend) ExtendWorkflowTask(ctx context.Context, instance workflow.Instance) error {
377378
tx, err := sb.db.BeginTx(ctx, nil)
378379
if err != nil {
379380
return err
@@ -460,7 +461,7 @@ func (sb *sqliteBackend) GetActivityTask(ctx context.Context) (*task.Activity, e
460461
return t, nil
461462
}
462463

463-
func (sb *sqliteBackend) CompleteActivityTask(ctx context.Context, instance core.WorkflowInstance, id string, event history.Event) error {
464+
func (sb *sqliteBackend) CompleteActivityTask(ctx context.Context, instance workflow.Instance, id string, event history.Event) error {
464465
tx, err := sb.db.BeginTx(ctx, nil)
465466
if err != nil {
466467
return err

client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type WorkflowInstanceOptions struct {
2020
}
2121

2222
type Client interface {
23-
CreateWorkflowInstance(ctx context.Context, options WorkflowInstanceOptions, wf workflow.Workflow, args ...interface{}) (workflow.WorkflowInstance, error)
23+
CreateWorkflowInstance(ctx context.Context, options WorkflowInstanceOptions, wf workflow.Workflow, args ...interface{}) (workflow.Instance, error)
2424

25-
CancelWorkflowInstance(ctx context.Context, instance workflow.WorkflowInstance) error
25+
CancelWorkflowInstance(ctx context.Context, instance workflow.Instance) error
2626

2727
SignalWorkflow(ctx context.Context, instanceID string, name string, arg interface{}) error
2828
}
@@ -37,7 +37,7 @@ func New(backend backend.Backend) Client {
3737
}
3838
}
3939

40-
func (c *client) CreateWorkflowInstance(ctx context.Context, options WorkflowInstanceOptions, wf workflow.Workflow, args ...interface{}) (workflow.WorkflowInstance, error) {
40+
func (c *client) CreateWorkflowInstance(ctx context.Context, options WorkflowInstanceOptions, wf workflow.Workflow, args ...interface{}) (workflow.Instance, error) {
4141
inputs, err := a.ArgsToInputs(converter.DefaultConverter, args...)
4242
if err != nil {
4343
return nil, errors.Wrap(err, "could not convert arguments")
@@ -65,7 +65,7 @@ func (c *client) CreateWorkflowInstance(ctx context.Context, options WorkflowIns
6565
return wfi, nil
6666
}
6767

68-
func (c *client) CancelWorkflowInstance(ctx context.Context, instance workflow.WorkflowInstance) error {
68+
func (c *client) CancelWorkflowInstance(ctx context.Context, instance workflow.Instance) error {
6969
return c.backend.CancelWorkflowInstance(ctx, instance)
7070
}
7171

workflow/workflow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
type (
12-
WorkflowInstance = core.WorkflowInstance
12+
Instance = core.WorkflowInstance
1313
Workflow = internal.Workflow
1414
SubWorkflowOptions = internal.SubWorkflowOptions
1515
Activity = internal.Activity
@@ -49,7 +49,7 @@ func NewSignalChannel(ctx Context, name string) Channel {
4949
}
5050

5151
// TODO: Rename
52-
func WorkflowInstance2(ctx Context) WorkflowInstance {
52+
func WorkflowInstance2(ctx Context) Instance {
5353
return internal.WorkflowInstance2(ctx)
5454
}
5555

0 commit comments

Comments
 (0)