Skip to content

Commit 80a15b9

Browse files
committed
Merge branch 'organize-packages'
2 parents 7523acf + 56040fc commit 80a15b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+254
-252
lines changed

pkg/backend/backend.go renamed to backend/backend.go

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

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

1111
//go:generate mockery --name=Backend --inpackage
1212
type Backend interface {
1313
// CreateWorkflowInstance creates a new workflow instance
14-
CreateWorkflowInstance(ctx context.Context, event core.WorkflowEvent) error
14+
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 []core.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

pkg/backend/mock_Backend.go renamed to backend/mock_Backend.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/backend/mysql/events.go renamed to backend/mysql/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"database/sql"
66
"strings"
77

8-
"github.com/cschleiden/go-workflows/pkg/history"
8+
"github.com/cschleiden/go-workflows/internal/history"
99
)
1010

1111
func insertNewEvents(ctx context.Context, tx *sql.Tx, instanceID string, newEvents []history.Event) error {

pkg/backend/mysql/mysql.go renamed to backend/mysql/mysql.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/cschleiden/go-workflows/pkg/backend"
12-
"github.com/cschleiden/go-workflows/pkg/core"
13-
"github.com/cschleiden/go-workflows/pkg/core/task"
14-
"github.com/cschleiden/go-workflows/pkg/history"
11+
"github.com/cschleiden/go-workflows/backend"
12+
"github.com/cschleiden/go-workflows/internal/core"
13+
"github.com/cschleiden/go-workflows/internal/history"
14+
"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"
@@ -56,7 +57,7 @@ type mysqlBackend struct {
5657
}
5758

5859
// CreateWorkflowInstance creates a new workflow instance
59-
func (b *mysqlBackend) CreateWorkflowInstance(ctx context.Context, m core.WorkflowEvent) error {
60+
func (b *mysqlBackend) CreateWorkflowInstance(ctx context.Context, m history.WorkflowEvent) error {
6061
tx, err := b.db.BeginTx(ctx, nil)
6162
if err != nil {
6263
return errors.Wrap(err, "could not start transaction")
@@ -80,7 +81,7 @@ func (b *mysqlBackend) CreateWorkflowInstance(ctx context.Context, m core.Workfl
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,9 +359,9 @@ 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,
363-
workflowEvents []core.WorkflowEvent,
364+
workflowEvents []history.WorkflowEvent,
364365
) error {
365366
tx, err := b.db.BeginTx(ctx, &sql.TxOptions{
366367
Isolation: sql.LevelReadCommitted,
@@ -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

pkg/backend/mysql/mysql_test.go renamed to backend/mysql/mysql_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"strings"
77
"testing"
88

9-
"github.com/cschleiden/go-workflows/pkg/backend"
10-
"github.com/cschleiden/go-workflows/pkg/backend/test"
9+
"github.com/cschleiden/go-workflows/backend"
10+
"github.com/cschleiden/go-workflows/backend/test"
1111
"github.com/google/uuid"
1212
"github.com/pkg/errors"
1313
)
File renamed without changes.
File renamed without changes.

pkg/backend/sqlite/activities.go renamed to backend/sqlite/activities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"database/sql"
66

7-
"github.com/cschleiden/go-workflows/pkg/history"
7+
"github.com/cschleiden/go-workflows/internal/history"
88
)
99

1010
func scheduleActivity(ctx context.Context, tx *sql.Tx, instanceID, executionID string, event history.Event) error {

pkg/backend/sqlite/events.go renamed to backend/sqlite/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
"time"
88

9-
"github.com/cschleiden/go-workflows/pkg/history"
9+
"github.com/cschleiden/go-workflows/internal/history"
1010
"github.com/pkg/errors"
1111
)
1212

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
CREATE TABLE IF NOT EXISTS `instances` (
2-
`id` TEXT PRIMARY KEY,
3-
`execution_id` TEXT NO NULL,
4-
`parent_instance_id` TEXT NULL,
5-
`parent_schedule_event_id` INTEGER NULL,
6-
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
7-
`completed_at` DATETIME NULL,
8-
`locked_until` DATETIME NULL,
9-
`sticky_until` DATETIME NULL,
10-
`worker` TEXT NULL
11-
12-
);
13-
14-
CREATE INDEX IF NOT EXISTS `idx_instances_locked_until_completed_at` ON `instances` (`locked_until`, `sticky_until`, `completed_at`, `worker`);
15-
CREATE INDEX IF NOT EXISTS `idx_instances_parent_instance_id` ON `instances` (`parent_instance_id`);
16-
17-
CREATE TABLE IF NOT EXISTS `pending_events` (
18-
`id` TEXT PRIMARY KEY,
19-
`instance_id` TEXT NOT NULL,
20-
`event_type` INTEGER NOT NULL,
21-
`timestamp` DATETIME NOT NULL,
22-
`schedule_event_id` INT NOT NULL,
23-
`attributes` BLOB NOT NULL,
24-
`visible_at` DATETIME NULL
25-
);
26-
27-
CREATE TABLE IF NOT EXISTS `history` (
28-
`id` TEXT PRIMARY KEY,
29-
`instance_id` TEXT NOT NULL,
30-
`event_type` INTEGER NOT NULL,
31-
`timestamp` DATETIME NOT NULL,
32-
`schedule_event_id` INT NOT NULL,
33-
`attributes` BLOB NOT NULL,
34-
`visible_at` DATETIME NULL
35-
);
36-
37-
CREATE TABLE IF NOT EXISTS `activities` (
38-
`id` TEXT PRIMARY KEY,
39-
`instance_id` TEXT NOT NULL,
40-
`execution_id` TEXT NOT NULL,
41-
`event_type` INTEGER NOT NULL,
42-
`timestamp` DATETIME NOT NULL,
43-
`schedule_event_id` INT NOT NULL,
44-
`attributes` BLOB NOT NULL,
45-
`visible_at` DATETIME NULL,
46-
`locked_until` DATETIME NULL,
47-
`worker` TEXT NULL
1+
CREATE TABLE IF NOT EXISTS `instances` (
2+
`id` TEXT PRIMARY KEY,
3+
`execution_id` TEXT NO NULL,
4+
`parent_instance_id` TEXT NULL,
5+
`parent_schedule_event_id` INTEGER NULL,
6+
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
7+
`completed_at` DATETIME NULL,
8+
`locked_until` DATETIME NULL,
9+
`sticky_until` DATETIME NULL,
10+
`worker` TEXT NULL
11+
12+
);
13+
14+
CREATE INDEX IF NOT EXISTS `idx_instances_locked_until_completed_at` ON `instances` (`locked_until`, `sticky_until`, `completed_at`, `worker`);
15+
CREATE INDEX IF NOT EXISTS `idx_instances_parent_instance_id` ON `instances` (`parent_instance_id`);
16+
17+
CREATE TABLE IF NOT EXISTS `pending_events` (
18+
`id` TEXT PRIMARY KEY,
19+
`instance_id` TEXT NOT NULL,
20+
`event_type` INTEGER NOT NULL,
21+
`timestamp` DATETIME NOT NULL,
22+
`schedule_event_id` INT NOT NULL,
23+
`attributes` BLOB NOT NULL,
24+
`visible_at` DATETIME NULL
25+
);
26+
27+
CREATE TABLE IF NOT EXISTS `history` (
28+
`id` TEXT PRIMARY KEY,
29+
`instance_id` TEXT NOT NULL,
30+
`event_type` INTEGER NOT NULL,
31+
`timestamp` DATETIME NOT NULL,
32+
`schedule_event_id` INT NOT NULL,
33+
`attributes` BLOB NOT NULL,
34+
`visible_at` DATETIME NULL
35+
);
36+
37+
CREATE TABLE IF NOT EXISTS `activities` (
38+
`id` TEXT PRIMARY KEY,
39+
`instance_id` TEXT NOT NULL,
40+
`execution_id` TEXT NOT NULL,
41+
`event_type` INTEGER NOT NULL,
42+
`timestamp` DATETIME NOT NULL,
43+
`schedule_event_id` INT NOT NULL,
44+
`attributes` BLOB NOT NULL,
45+
`visible_at` DATETIME NULL,
46+
`locked_until` DATETIME NULL,
47+
`worker` TEXT NULL
4848
);

0 commit comments

Comments
 (0)