[hw-6] add notifier service, kafka

This commit is contained in:
Никита Шубин
2025-07-17 19:20:27 +00:00
parent 424d6905da
commit 6e1ad86128
33 changed files with 1412 additions and 92 deletions

View File

@@ -0,0 +1,42 @@
package service
import (
"context"
"time"
"github.com/rs/zerolog/log"
)
type StatusConsumer interface {
FetchEvents(ctx context.Context) error
}
type NotifierService struct {
consumer StatusConsumer
}
func NewNotifierService(consumer StatusConsumer) *NotifierService {
return &NotifierService{
consumer: consumer,
}
}
func (s *NotifierService) RunFetchEvents(ctx context.Context) error {
backoff := 1 * time.Second
for {
if err := s.consumer.FetchEvents(ctx); err != nil {
if ctx.Err() != nil {
return ctx.Err()
}
log.Error().Err(err).Msgf("consume error (retrying in %d second(s))", backoff)
}
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(backoff):
}
}
}