Skip to content

Commit 6fa3384

Browse files
authored
feat: add publishers and upgrade GoAkt to 3.0.0 (#125)
1 parent 6f217d5 commit 6fa3384

Some content is hidden

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

80 files changed

+5338
-577
lines changed

.github/workflows/build.yml

-6
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,3 @@ jobs:
5353
files: ./coverage.out # optional
5454
fail_ci_if_error: false # optional (default = false)
5555
verbose: false # optional (default = false)
56-
# - uses: go-semantic-release/action@v1
57-
# id: semver
58-
# with:
59-
# github-token: ${{ secrets.GITHUB_TOKEN }}
60-
# allow-initial-development-versions: true
61-
# force-bump-patch-version: true

.github/workflows/codeql-analysis.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ main ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ main ]
20+
schedule:
21+
- cron: '28 20 * * 0'
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
analyze:
29+
name: Analyze
30+
runs-on: ubuntu-latest
31+
permissions:
32+
actions: read
33+
contents: read
34+
security-events: write
35+
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
language: [ 'go' ]
40+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
41+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
42+
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
47+
# Initializes the CodeQL tools for scanning.
48+
- name: Initialize CodeQL
49+
uses: github/codeql-action/init@v3
50+
with:
51+
languages: ${{ matrix.language }}
52+
# If you wish to specify custom queries, you can do so here or in a config file.
53+
# By default, queries listed here will override any specified in a config file.
54+
# Prefix the list here with "+" to use these queries and those in the config file.
55+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
56+
57+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
58+
# If this step fails, then you should remove it and run the build manually (see below)
59+
- name: Autobuild
60+
uses: github/codeql-action/autobuild@v3
61+
62+
# ℹ️ Command-line programs to run using the OS shell.
63+
# 📚 https://git.io/JvXDl
64+
65+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
66+
# and modify them (or add more) to build your code if your project
67+
# uses a compiled language
68+
69+
#- run: |
70+
# make bootstrap
71+
# make release
72+
73+
- name: Perform CodeQL Analysis
74+
uses: github/codeql-action/analyze@v3

.golangci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ issues:
3939
- revive
4040

4141
linters-settings:
42+
gosec:
43+
excludes:
44+
- G115
4245
misspell:
4346
locale: US
4447
ignore-words:

Earthfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
VERSION 0.8
22

3-
FROM tochemey/docker-go:1.22.0-3.0.0
3+
FROM tochemey/docker-go:1.23.4-5.1.1
44

55
RUN go install github.com/ory/go-acc@latest
6+
# install vektra/mockery
7+
RUN go install github.com/vektra/mockery/[email protected]
68

79
protogen:
810
# copy the proto files to generate
@@ -92,6 +94,8 @@ mock:
9294
# generate the mocks
9395
RUN mockery --dir persistence --all --keeptree --exported=true --with-expecter=true --inpackage=true --disable-version-string=true --output ./mocks/persistence --case snake
9496
RUN mockery --dir offsetstore --name OffsetStore --keeptree --exported=true --with-expecter=true --inpackage=true --disable-version-string=true --output ./mocks/offsetstore --case snake
97+
RUN mockery --dir . --name EventPublisher --keeptree --exported=true --with-expecter=true --inpackage=true --disable-version-string=true --output ./mocks/ego --case snake
98+
RUN mockery --dir . --name StatePublisher --keeptree --exported=true --with-expecter=true --inpackage=true --disable-version-string=true --output ./mocks/ego --case snake
9599

96100

97101
SAVE ARTIFACT ./mocks mocks AS LOCAL mocks

behavior.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MIT License
33
*
4-
* Copyright (c) 2022-2025 Arsene Tochemey Gandote
4+
* Copyright (c) 2023-2025 Tochemey
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

durable_state_actor.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MIT License
33
*
4-
* Copyright (c) 2022-2025 Arsene Tochemey Gandote
4+
* Copyright (c) 2023-2025 Tochemey
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -30,8 +30,8 @@ import (
3030
"math"
3131
"time"
3232

33-
"github.com/tochemey/goakt/v2/actors"
34-
"github.com/tochemey/goakt/v2/goaktpb"
33+
goakt "github.com/tochemey/goakt/v3/actor"
34+
"github.com/tochemey/goakt/v3/goaktpb"
3535
"golang.org/x/sync/errgroup"
3636
"google.golang.org/protobuf/proto"
3737
"google.golang.org/protobuf/types/known/anypb"
@@ -55,11 +55,11 @@ type durableStateActor struct {
5555
currentVersion uint64
5656
lastCommandTime time.Time
5757
eventsStream eventstream.Stream
58-
actorSystem actors.ActorSystem
58+
actorSystem goakt.ActorSystem
5959
}
6060

61-
// implements the actors.Actor interface
62-
var _ actors.Actor = (*durableStateActor)(nil)
61+
// implements the goakt.Actor interface
62+
var _ goakt.Actor = (*durableStateActor)(nil)
6363

6464
// newDurableStateActor creates an instance of actor provided the DurableStateBehavior
6565
func newDurableStateActor(behavior DurableStateBehavior, stateStore persistence.StateStore, eventsStream eventstream.Stream) *durableStateActor {
@@ -81,7 +81,7 @@ func (entity *durableStateActor) PreStart(ctx context.Context) error {
8181
}
8282

8383
// Receive processes any message dropped into the actor mailbox.
84-
func (entity *durableStateActor) Receive(ctx *actors.ReceiveContext) {
84+
func (entity *durableStateActor) Receive(ctx *goakt.ReceiveContext) {
8585
switch command := ctx.Message().(type) {
8686
case *goaktpb.PostStart:
8787
entity.actorSystem = ctx.ActorSystem()
@@ -125,7 +125,7 @@ func (entity *durableStateActor) recoverFromStore(ctx context.Context) error {
125125
}
126126

127127
// processCommand processes the incoming command
128-
func (entity *durableStateActor) processCommand(receiveContext *actors.ReceiveContext, command Command) {
128+
func (entity *durableStateActor) processCommand(receiveContext *goakt.ReceiveContext, command Command) {
129129
ctx := receiveContext.Context()
130130
newState, newVersion, err := entity.HandleCommand(ctx, command, entity.currentVersion, entity.currentState)
131131
if err != nil {
@@ -153,7 +153,7 @@ func (entity *durableStateActor) processCommand(receiveContext *actors.ReceiveCo
153153
}
154154

155155
// sendStateReply sends a state reply message
156-
func (entity *durableStateActor) sendStateReply(ctx *actors.ReceiveContext) {
156+
func (entity *durableStateActor) sendStateReply(ctx *goakt.ReceiveContext) {
157157
state, _ := anypb.New(entity.currentState)
158158
ctx.Response(&egopb.CommandReply{
159159
Reply: &egopb.CommandReply_StateReply{
@@ -168,7 +168,7 @@ func (entity *durableStateActor) sendStateReply(ctx *actors.ReceiveContext) {
168168
}
169169

170170
// sendErrorReply sends an error as a reply message
171-
func (entity *durableStateActor) sendErrorReply(ctx *actors.ReceiveContext, err error) {
171+
func (entity *durableStateActor) sendErrorReply(ctx *goakt.ReceiveContext, err error) {
172172
ctx.Response(&egopb.CommandReply{
173173
Reply: &egopb.CommandReply_ErrorReply{
174174
ErrorReply: &egopb.ErrorReply{
@@ -211,6 +211,8 @@ func (entity *durableStateActor) persistStateAndPublish(ctx context.Context) err
211211
shardNumber := entity.actorSystem.GetPartition(entity.ID())
212212
topic := fmt.Sprintf(statesTopic, shardNumber)
213213

214+
entity.actorSystem.Logger().Debugf("publishing durableState to topic: %s", topic)
215+
214216
durableState := &egopb.DurableState{
215217
PersistenceId: entity.ID(),
216218
VersionNumber: entity.currentVersion,

durable_state_actor_test.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MIT License
33
*
4-
* Copyright (c) 2022-2025 Arsene Tochemey Gandote
4+
* Copyright (c) 2023-2025 Tochemey
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -32,8 +32,8 @@ import (
3232
"github.com/google/uuid"
3333
"github.com/stretchr/testify/assert"
3434
"github.com/stretchr/testify/require"
35-
"github.com/tochemey/goakt/v2/actors"
36-
"github.com/tochemey/goakt/v2/log"
35+
goakt "github.com/tochemey/goakt/v3/actor"
36+
"github.com/tochemey/goakt/v3/log"
3737
"google.golang.org/protobuf/proto"
3838

3939
"github.com/tochemey/ego/v3/egopb"
@@ -47,10 +47,10 @@ func TestDurableStateBehavior(t *testing.T) {
4747
t.Run("with state reply", func(t *testing.T) {
4848
ctx := context.TODO()
4949
// create an actor system
50-
actorSystem, err := actors.NewActorSystem("TestActorSystem",
51-
actors.WithPassivationDisabled(),
52-
actors.WithLogger(log.DiscardLogger),
53-
actors.WithActorInitMaxRetries(3))
50+
actorSystem, err := goakt.NewActorSystem("TestActorSystem",
51+
goakt.WithPassivationDisabled(),
52+
goakt.WithLogger(log.DiscardLogger),
53+
goakt.WithActorInitMaxRetries(3))
5454
require.NoError(t, err)
5555
assert.NotNil(t, actorSystem)
5656

@@ -80,7 +80,7 @@ func TestDurableStateBehavior(t *testing.T) {
8080

8181
command = &testpb.CreateAccount{AccountBalance: 500.00}
8282
// send the command to the actor
83-
reply, err := actors.Ask(ctx, pid, command, 5*time.Second)
83+
reply, err := goakt.Ask(ctx, pid, command, 5*time.Second)
8484
require.NoError(t, err)
8585
require.NotNil(t, reply)
8686
require.IsType(t, new(egopb.CommandReply), reply)
@@ -107,7 +107,7 @@ func TestDurableStateBehavior(t *testing.T) {
107107
AccountId: persistenceID,
108108
Balance: 250,
109109
}
110-
reply, err = actors.Ask(ctx, pid, command, 5*time.Second)
110+
reply, err = goakt.Ask(ctx, pid, command, 5*time.Second)
111111
require.NoError(t, err)
112112
require.NotNil(t, reply)
113113
require.IsType(t, new(egopb.CommandReply), reply)
@@ -143,10 +143,10 @@ func TestDurableStateBehavior(t *testing.T) {
143143
ctx := context.TODO()
144144

145145
// create an actor system
146-
actorSystem, err := actors.NewActorSystem("TestActorSystem",
147-
actors.WithPassivationDisabled(),
148-
actors.WithLogger(log.DiscardLogger),
149-
actors.WithActorInitMaxRetries(3))
146+
actorSystem, err := goakt.NewActorSystem("TestActorSystem",
147+
goakt.WithPassivationDisabled(),
148+
goakt.WithLogger(log.DiscardLogger),
149+
goakt.WithActorInitMaxRetries(3))
150150
require.NoError(t, err)
151151
assert.NotNil(t, actorSystem)
152152

@@ -182,7 +182,7 @@ func TestDurableStateBehavior(t *testing.T) {
182182

183183
command = &testpb.CreateAccount{AccountBalance: 500.00}
184184
// send the command to the actor
185-
reply, err := actors.Ask(ctx, pid, command, time.Second)
185+
reply, err := goakt.Ask(ctx, pid, command, time.Second)
186186
require.NoError(t, err)
187187
require.NotNil(t, reply)
188188
require.IsType(t, new(egopb.CommandReply), reply)
@@ -209,7 +209,7 @@ func TestDurableStateBehavior(t *testing.T) {
209209
AccountId: "different-id",
210210
Balance: 250,
211211
}
212-
reply, err = actors.Ask(ctx, pid, command, time.Second)
212+
reply, err = goakt.Ask(ctx, pid, command, time.Second)
213213
require.NoError(t, err)
214214
require.NotNil(t, reply)
215215
require.IsType(t, new(egopb.CommandReply), reply)
@@ -231,10 +231,10 @@ func TestDurableStateBehavior(t *testing.T) {
231231
})
232232
t.Run("with state recovery from state store", func(t *testing.T) {
233233
ctx := context.TODO()
234-
actorSystem, err := actors.NewActorSystem("TestActorSystem",
235-
actors.WithPassivationDisabled(),
236-
actors.WithLogger(log.DiscardLogger),
237-
actors.WithActorInitMaxRetries(3),
234+
actorSystem, err := goakt.NewActorSystem("TestActorSystem",
235+
goakt.WithPassivationDisabled(),
236+
goakt.WithLogger(log.DiscardLogger),
237+
goakt.WithActorInitMaxRetries(3),
238238
)
239239
require.NoError(t, err)
240240
assert.NotNil(t, actorSystem)
@@ -271,7 +271,7 @@ func TestDurableStateBehavior(t *testing.T) {
271271

272272
command = &testpb.CreateAccount{AccountBalance: 500.00}
273273

274-
reply, err := actors.Ask(ctx, pid, command, time.Second)
274+
reply, err := goakt.Ask(ctx, pid, command, time.Second)
275275
require.NoError(t, err)
276276
require.NotNil(t, reply)
277277
require.IsType(t, new(egopb.CommandReply), reply)
@@ -298,7 +298,7 @@ func TestDurableStateBehavior(t *testing.T) {
298298
AccountId: persistenceID,
299299
Balance: 250,
300300
}
301-
reply, err = actors.Ask(ctx, pid, command, time.Second)
301+
reply, err = goakt.Ask(ctx, pid, command, time.Second)
302302
require.NoError(t, err)
303303
require.NotNil(t, reply)
304304
require.IsType(t, new(egopb.CommandReply), reply)
@@ -331,7 +331,7 @@ func TestDurableStateBehavior(t *testing.T) {
331331

332332
// fetch the current state
333333
command = &egopb.GetStateCommand{}
334-
reply, err = actors.Ask(ctx, pid, command, time.Second)
334+
reply, err = goakt.Ask(ctx, pid, command, time.Second)
335335
require.NoError(t, err)
336336
require.NotNil(t, reply)
337337
require.IsType(t, new(egopb.CommandReply), reply)

0 commit comments

Comments
 (0)