mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-03 13:37:52 +02:00
More RPC-related logs (#136)
* More RPC-related logs * Notifier should be set before we use it in the scheduler
This commit is contained in:
@@ -58,7 +58,6 @@ type Controller struct {
|
||||
|
||||
func New(opts ...Option) (*Controller, error) {
|
||||
controller := &Controller{
|
||||
workerNotifier: notifier.NewNotifier(),
|
||||
proxy: proxy.NewProxy(),
|
||||
workerOfflineTimeout: 3 * time.Minute,
|
||||
maxWorkersPerLicense: maxWorkersPerDefaultLicense,
|
||||
@@ -101,6 +100,7 @@ func New(opts ...Option) (*Controller, error) {
|
||||
return nil, err
|
||||
}
|
||||
controller.store = store
|
||||
controller.workerNotifier = notifier.NewNotifier(controller.logger.With("component", "rpc"))
|
||||
controller.scheduler = scheduler.NewScheduler(store, controller.workerNotifier,
|
||||
controller.workerOfflineTimeout, controller.logger)
|
||||
|
||||
|
||||
@@ -6,12 +6,14 @@ import (
|
||||
"fmt"
|
||||
"github.com/cirruslabs/orchard/internal/concurrentmap"
|
||||
"github.com/cirruslabs/orchard/rpc"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var ErrNoWorker = errors.New("no worker registered with this name")
|
||||
|
||||
type Notifier struct {
|
||||
workers *concurrentmap.ConcurrentMap[*WorkerSlot]
|
||||
logger *zap.SugaredLogger
|
||||
}
|
||||
|
||||
type WorkerSlot struct {
|
||||
@@ -19,9 +21,10 @@ type WorkerSlot struct {
|
||||
ch chan *rpc.WatchInstruction
|
||||
}
|
||||
|
||||
func NewNotifier() *Notifier {
|
||||
func NewNotifier(logger *zap.SugaredLogger) *Notifier {
|
||||
return &Notifier{
|
||||
workers: concurrentmap.NewConcurrentMap[*WorkerSlot](),
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +32,14 @@ func (watcher *Notifier) Register(ctx context.Context, worker string) (chan *rpc
|
||||
subCtx, cancel := context.WithCancel(ctx)
|
||||
workerCh := make(chan *rpc.WatchInstruction)
|
||||
|
||||
watcher.logger.Debugf("registering worker %s", worker)
|
||||
watcher.workers.Store(worker, &WorkerSlot{
|
||||
ctx: subCtx,
|
||||
ch: workerCh,
|
||||
})
|
||||
|
||||
return workerCh, func() {
|
||||
watcher.logger.Debugf("deleting worker %s", worker)
|
||||
watcher.workers.Delete(worker)
|
||||
cancel()
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/cirruslabs/orchard/internal/controller/notifier"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
func TestNotifier(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
notifier := notifier.NewNotifier()
|
||||
notifier := notifier.NewNotifier(zap.NewNop().Sugar())
|
||||
|
||||
var topic = uuid.New().String()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user