Files
warmbly/internal/app/worker/receive.go
T
Matthew Meszaros 35fc12b624 worker+events: route through EventBus + Codec, drop direct Kafka coupling
WorkerService now holds eventbus.EventBus + codec.Codec instead of
*kafka.Producer / *kafka.Consumer. Receive() satisfies the
eventbus.Handler signature; Produce() goes through Codec.Serialize +
Bus.Publish.

events.Publisher likewise switches to (bus, codec) and stops
serializing via *kafka.Avrov2 directly.

The kafka package and its Avrov2/Producer/Consumer types remain for
the few non-worker call sites (tracking consumer, validate_credentials)
that haven't been migrated yet; bundled with KafkaBus.Producer() so
existing Avro framing on Kafka is preserved.

Worker boot wiring is split into cmd/* entry-point commits.
2026-05-27 14:43:03 +00:00

24 lines
647 B
Go

package worker
import (
"context"
"time"
"github.com/warmbly/warmbly/internal/infrastructure/eventbus"
"github.com/warmbly/warmbly/internal/models"
)
// Receive is the eventbus.Handler that drives the worker's event loop. It
// decodes the wire payload via the injected codec.Codec and dispatches to
// HandleEvent.
func (w *WorkerService) Receive(ctx context.Context, msg eventbus.Message) error {
var event models.WorkerEvent
if err := w.Codec.Deserialize(ctx, msg.Topic, msg.Payload, &event); err != nil {
return err
}
hctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
return w.HandleEvent(hctx, &event)
}