feat: deliver authenticated merchant analytics API
This commit is contained in:
33
cmd/worker/main.go
Normal file
33
cmd/worker/main.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/config"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
logger.Error("configuration failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer cancel()
|
||||
client := redis.NewClient(&redis.Options{Addr: cfg.RedisAddr, Password: cfg.RedisPassword})
|
||||
defer client.Close()
|
||||
pingCtx, pingCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer pingCancel()
|
||||
if err := client.Ping(pingCtx).Err(); err != nil {
|
||||
logger.Error("redis connection failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.Info("analytics worker ready", "redis_address", cfg.RedisAddr)
|
||||
<-ctx.Done()
|
||||
}
|
||||
Reference in New Issue
Block a user