kacarmichael 309eeef59a
Some checks failed
Build Go Binaries / build (push) Has been cancelled
Health/status http endpoint, logging
2026-08-06 01:24:29 -05:00

43 lines
1.3 KiB
Go

package processor
import (
"context"
"log"
"m3u8-downloader/pkg/constants"
"m3u8-downloader/pkg/health"
"m3u8-downloader/pkg/logging"
"m3u8-downloader/pkg/processing"
"time"
)
func Process(eventName string) {
appLog := logging.MustGetFactory().App
log.Printf("Starting processing for event: %s", eventName)
appLog.Info("starting processing", logging.KeyEvent, eventName)
cfg := constants.MustGetConfig()
if cfg.Health.Enabled {
healthSrv, err := health.Start(context.Background(), &cfg.Health, health.MustGetRegistry())
if err != nil {
appLog.Error("failed to start health server", logging.KeyError, err.Error())
} else {
appLog.Info("health server listening", "addr", cfg.Health.Addr)
defer func() {
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer shutdownCancel()
_ = healthSrv.Shutdown(shutdownCtx)
}()
}
}
ps, err := processing.NewProcessingService(eventName, cfg)
if err != nil {
appLog.Error("failed to create processing service", logging.KeyError, err.Error())
log.Fatalf("Failed to create processing service: %v", err)
}
if err := ps.Start(context.Background()); err != nil {
appLog.Error("processing service failed", logging.KeyError, err.Error())
log.Fatalf("Failed to run processing service: %v", err)
}
}