Skip to content

Commit

Permalink
expose internal worker identifier for unicast task delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd committed Oct 21, 2023
1 parent 5641df0 commit a2c867e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions engine/worker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package engine

func (e *Engine) Worker() string {
return e.wrk
}
47 changes: 47 additions & 0 deletions engine/worker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package engine

import (
"fmt"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/xh3b4sd/redigo"
)

func Test_Engine_Worker(t *testing.T) {
testCases := []struct {
wrk string
}{
// Case 000
{
wrk: "foo",
},
// Case 001
{
wrk: "bar",
},
// Case 002
{
wrk: "123",
},
}

for i, tc := range testCases {
t.Run(fmt.Sprintf("%03d", i), func(t *testing.T) {
var e *Engine
{
e = New(Config{
Redigo: redigo.Fake(),
Worker: tc.wrk,
})
}

wrk := e.Worker()

if !reflect.DeepEqual(wrk, tc.wrk) {
t.Fatalf("\n\n%s\n", cmp.Diff(tc.wrk, wrk))
}
})
}
}
4 changes: 4 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ type Interface interface {
// multiple workers, it takes only a single functioning worker to call ticker
// in order to keep scheduling recurring tasks for anyone to work on.
Ticker() error

// Worker returns the this worker's identifier, which may be used for unicast
// style task delivery.
Worker() string
}

0 comments on commit a2c867e

Please sign in to comment.