34 lines
874 B
Go
34 lines
874 B
Go
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()
|
|
}
|