tercul-backend/internal/cmd/enrich/main.go
Damir Mukimov 4957117cb6 Initial commit: Tercul Go project with comprehensive architecture
- Core Go application with GraphQL API using gqlgen
- Comprehensive data models for literary works, authors, translations
- Repository pattern with caching layer
- Authentication and authorization system
- Linguistics analysis capabilities with multiple adapters
- Vector search integration with Weaviate
- Docker containerization support
- Python data migration and analysis scripts
- Clean architecture with proper separation of concerns
- Production-ready configuration and middleware
- Proper .gitignore excluding vendor/, database files, and build artifacts
2025-08-13 07:42:32 +02:00

76 lines
1.6 KiB
Go

package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"time"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"tercul/config"
"tercul/internal/enrich"
"tercul/internal/store"
)
func main() {
log.Println("Starting enrichment service...")
// Create a context that can be cancelled
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Set up signal handling
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigCh
log.Printf("Received signal %v, shutting down...", sig)
cancel()
}()
// Load configuration
config.LoadConfig()
// Connect to the database
dsn := os.Getenv("DATABASE_URL")
if dsn == "" {
dsn = config.Cfg.GetDSN()
}
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
// Create a store.DB
storeDB := &store.DB{DB: db}
// Create the enrichment registry
registry := enrich.DefaultRegistry()
// Process pending works
if err := store.ProcessPendingWorks(ctx, registry, storeDB); err != nil {
log.Fatalf("Failed to process pending works: %v", err)
}
// Set up a ticker to periodically process pending works
ticker := time.NewTicker(5 * time.Minute)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
log.Println("Shutting down...")
return
case <-ticker.C:
log.Println("Processing pending works...")
if err := store.ProcessPendingWorks(ctx, registry, storeDB); err != nil {
log.Printf("Failed to process pending works: %v", err)
}
}
}
}