Skip to content

Commit

Permalink
workflow: Use smaller logger dependency with override support
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwormald committed Sep 2, 2024
1 parent b165d66 commit d20568b
Show file tree
Hide file tree
Showing 61 changed files with 576 additions and 335 deletions.
2 changes: 1 addition & 1 deletion _examples/callback/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Deps struct {
func ExampleWorkflow(d Deps) *workflow.Workflow[Example, Status] {
b := workflow.NewBuilder[Example, Status]("callback example")

b.AddCallback(StatusStarted, func(ctx context.Context, r *workflow.Record[Example, Status], reader io.Reader) (Status, error) {
b.AddCallback(StatusStarted, func(ctx context.Context, r *workflow.Run[Example, Status], reader io.Reader) (Status, error) {
b, err := io.ReadAll(reader)
if err != nil {
return 0, err
Expand Down
4 changes: 2 additions & 2 deletions _examples/callback/callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"testing"

"github.com/luno/jettison/jtest"
"github.com/luno/workflow"
"github.com/luno/workflow/adapters/memrecordstore"
"github.com/luno/workflow/adapters/memrolescheduler"
"github.com/luno/workflow/adapters/memstreamer"
"github.com/stretchr/testify/require"

"github.com/luno/workflow/_examples/callback"
)
Expand All @@ -26,7 +26,7 @@ func TestCallbackWorkflow(t *testing.T) {

foreignID := "andrew"
runID, err := wf.Trigger(ctx, foreignID, callback.StatusStarted)
jtest.RequireNil(t, err)
require.Nil(t, err)

workflow.TriggerCallbackOn(t, wf, foreignID, runID, callback.StatusStarted, callback.EmailConfirmationResponse{
Confirmed: true,
Expand Down
2 changes: 1 addition & 1 deletion _examples/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Workflow(d Deps) *workflow.Workflow[GettingStarted, Status] {
)

builder.AddStep(StatusStarted,
func(ctx context.Context, r *workflow.Record[GettingStarted, Status]) (Status, error) {
func(ctx context.Context, r *workflow.Run[GettingStarted, Status]) (Status, error) {
r.Object.FollowAnExample = "✅"

return StatusFollowedTheExample, nil
Expand Down
6 changes: 3 additions & 3 deletions _examples/gettingstarted/gettingstarted.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ type Deps struct {
func Workflow(d Deps) *workflow.Workflow[GettingStarted, Status] {
b := workflow.NewBuilder[GettingStarted, Status]("getting started")

b.AddStep(StatusStarted, func(ctx context.Context, r *workflow.Record[GettingStarted, Status]) (Status, error) {
b.AddStep(StatusStarted, func(ctx context.Context, r *workflow.Run[GettingStarted, Status]) (Status, error) {
r.Object.ReadTheDocs = "✅"
return StatusReadTheDocs, nil
}, StatusReadTheDocs)

b.AddStep(StatusReadTheDocs, func(ctx context.Context, r *workflow.Record[GettingStarted, Status]) (Status, error) {
b.AddStep(StatusReadTheDocs, func(ctx context.Context, r *workflow.Run[GettingStarted, Status]) (Status, error) {
r.Object.FollowAnExample = "✅"
return StatusFollowedTheExample, nil
}, StatusFollowedTheExample)

b.AddStep(StatusFollowedTheExample, func(ctx context.Context, r *workflow.Record[GettingStarted, Status]) (Status, error) {
b.AddStep(StatusFollowedTheExample, func(ctx context.Context, r *workflow.Run[GettingStarted, Status]) (Status, error) {
r.Object.CreateAFunExample = "✅"
return StatusCreatedAFunExample, nil
}, StatusCreatedAFunExample)
Expand Down
4 changes: 2 additions & 2 deletions _examples/gettingstarted/gettingstarted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"testing"

"github.com/luno/jettison/jtest"
"github.com/luno/workflow"
"github.com/luno/workflow/adapters/memrecordstore"
"github.com/luno/workflow/adapters/memrolescheduler"
"github.com/luno/workflow/adapters/memstreamer"
"github.com/luno/workflow/adapters/memtimeoutstore"
"github.com/stretchr/testify/require"

"github.com/luno/workflow/_examples/gettingstarted"
)
Expand All @@ -28,7 +28,7 @@ func TestWorkflow(t *testing.T) {

foreignID := "82347982374982374"
_, err := wf.Trigger(ctx, foreignID, gettingstarted.StatusStarted)
jtest.RequireNil(t, err)
require.Nil(t, err)

workflow.Require(t, wf, foreignID, gettingstarted.StatusReadTheDocs, gettingstarted.GettingStarted{
ReadTheDocs: "✅",
Expand Down
2 changes: 1 addition & 1 deletion _examples/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ExampleWorkflow(d Deps) *workflow.Workflow[Example, Status] {
b := workflow.NewBuilder[Example, Status]("schedule trigger example")

b.AddStep(StatusStarted,
func(ctx context.Context, r *workflow.Record[Example, Status]) (Status, error) {
func(ctx context.Context, r *workflow.Run[Example, Status]) (Status, error) {
return StatusFollowedTheExample, nil
},
StatusFollowedTheExample,
Expand Down
10 changes: 5 additions & 5 deletions _examples/schedule/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package schedule_test

import (
"context"
"errors"
"testing"
"time"

"github.com/luno/jettison/jtest"
"github.com/luno/workflow"
"github.com/luno/workflow/adapters/memrecordstore"
"github.com/luno/workflow/adapters/memrolescheduler"
Expand Down Expand Up @@ -37,23 +37,23 @@ func TestExampleWorkflow(t *testing.T) {

go func() {
err := wf.Schedule(foreignID, schedule.StatusStarted, "@hourly")
jtest.RequireNil(t, err)
require.Nil(t, err)
}()

// Give time for go routine to spin up
time.Sleep(200 * time.Millisecond)

_, err := recordStore.Latest(ctx, wf.Name, foreignID)
// Expect there to be no entries yet
jtest.Require(t, workflow.ErrRecordNotFound, err)
require.True(t, errors.Is(err, workflow.ErrRecordNotFound))

clock.Step(time.Hour)

// Allow scheduling to take place
time.Sleep(200 * time.Millisecond)

firstScheduled, err := recordStore.Latest(ctx, wf.Name, foreignID)
jtest.RequireNil(t, err)
require.Nil(t, err)

require.Equal(t, "schedule trigger example", firstScheduled.WorkflowName)
require.Equal(t, "hourly-run", firstScheduled.ForeignID)
Expand All @@ -64,7 +64,7 @@ func TestExampleWorkflow(t *testing.T) {
time.Sleep(200 * time.Millisecond)

secondScheduled, err := recordStore.Latest(ctx, wf.Name, foreignID)
jtest.RequireNil(t, err)
require.Nil(t, err)

require.Equal(t, "schedule trigger example", secondScheduled.WorkflowName)
require.Equal(t, "hourly-run", secondScheduled.ForeignID)
Expand Down
4 changes: 2 additions & 2 deletions _examples/timeout/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func ExampleWorkflow(d Deps) *workflow.Workflow[Example, Status] {
b := workflow.NewBuilder[Example, Status]("timeout example")

b.AddTimeout(StatusStarted,
func(ctx context.Context, r *workflow.Record[Example, Status], now time.Time) (time.Time, error) {
func(ctx context.Context, r *workflow.Run[Example, Status], now time.Time) (time.Time, error) {
// Using "now" over time.Now() allows for you to specify a clock for testing.
return now.Add(time.Hour), nil
},
func(ctx context.Context, r *workflow.Record[Example, Status], now time.Time) (Status, error) {
func(ctx context.Context, r *workflow.Run[Example, Status], now time.Time) (Status, error) {
r.Object.Now = now
return StatusFollowedTheExample, nil
},
Expand Down
4 changes: 2 additions & 2 deletions _examples/timeout/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"testing"
"time"

"github.com/luno/jettison/jtest"
"github.com/luno/workflow"
"github.com/luno/workflow/adapters/memrecordstore"
"github.com/luno/workflow/adapters/memrolescheduler"
"github.com/luno/workflow/adapters/memstreamer"
"github.com/luno/workflow/adapters/memtimeoutstore"
"github.com/stretchr/testify/require"
clocktesting "k8s.io/utils/clock/testing"

"github.com/luno/workflow/_examples/timeout"
Expand All @@ -33,7 +33,7 @@ func TestTimeoutWorkflow(t *testing.T) {

foreignID := "andrew"
runID, err := wf.Trigger(ctx, foreignID, timeout.StatusStarted)
jtest.RequireNil(t, err)
require.Nil(t, err)

workflow.AwaitTimeoutInsert(t, wf, foreignID, runID, timeout.StatusStarted)

Expand Down
5 changes: 2 additions & 3 deletions adapters/adaptertest/eventstreaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/google/uuid"
"github.com/luno/jettison/jtest"
"github.com/stretchr/testify/require"
clock_testing "k8s.io/utils/clock/testing"

Expand Down Expand Up @@ -91,14 +90,14 @@ func RunEventStreamerTest(t *testing.T, constructor workflow.EventStreamer) {
CountryCode: "GB",
}
runId, err := wf.Trigger(ctx, foreignID, SyncStatusStarted, workflow.WithInitialValue[User, SyncStatus](&u))
jtest.RequireNil(t, err)
require.Nil(t, err)

workflow.AwaitTimeoutInsert(t, wf, foreignID, runId, SyncStatusEmailSet)

clock.Step(time.Hour)

record, err := wf.Await(ctx, foreignID, runId, SyncStatusCompleted)
jtest.RequireNil(t, err)
require.Nil(t, err)

require.Equal(t, "[email protected]", record.Object.Email)
require.Equal(t, SyncStatusCompleted.String(), record.Status.String())
Expand Down
Loading

0 comments on commit d20568b

Please sign in to comment.