feat: stream and reconcile challenge dataset
This commit is contained in:
36
cmd/importer/main.go
Normal file
36
cmd/importer/main.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/config"
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/database"
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/importer"
|
||||
)
|
||||
|
||||
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()
|
||||
pool, err := database.Open(ctx, cfg.DatabaseURL)
|
||||
if err != nil {
|
||||
logger.Error("database connection failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer pool.Close()
|
||||
result, err := importer.Run(ctx, pool, cfg.ImportPath)
|
||||
if err != nil {
|
||||
logger.Error("import failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.Info("import complete", "noop", result.IsNoop, "source_sha256", result.SourceSHA256,
|
||||
"source_rows", result.SourceRows, "session_rows", result.SessionRows, "attempt_rows", result.AttemptRows)
|
||||
}
|
||||
Reference in New Issue
Block a user