mirror of
https://github.com/warmbly/warmbly.git
synced 2026-09-06 16:01:28 +00:00
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.
21 lines
495 B
Go
21 lines
495 B
Go
package worker
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/warmbly/warmbly/internal/infrastructure/kafka"
|
|
"github.com/warmbly/warmbly/internal/models"
|
|
)
|
|
|
|
func (s *WorkerService) Produce(jobEventType models.JobEventType, key string, body any) error {
|
|
ctx := context.Background()
|
|
payload, err := s.Codec.Serialize(ctx, kafka.TopicWorkerEvents, &models.JobEvent{
|
|
Type: jobEventType,
|
|
Body: body,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return s.Bus.Publish(ctx, kafka.TopicWorkerEvents, key, payload)
|
|
}
|