func main() { flag.Parse() log.SetOutput(os.Stdout) auth, err := aws.GetAuth("", "", "", time.Time{}) if err != nil { log.Fatalln("Failed to recieve auth") } stats, err := lib.InitStats(statsPrefix) if err != nil { log.Fatalln("Error initializing stats:", err) } postgresBackend, err := metadata.NewPostgresStorer(&pgConfig) listener := StartWorker(&listener.SQSAddr{ Region: aws.USWest2, QueueName: "spade-compactor-" + env, Auth: auth, }, stats, postgresBackend) wait := make(chan struct{}) sigc := make(chan os.Signal, 1) signal.Notify(sigc, syscall.SIGINT) go func() { <-sigc // Cause flush listener.Close() close(wait) }() <-wait }
func main() { flag.Parse() pgConfig.LoadAgeTrigger = time.Second * time.Duration(loadAgeSeconds) log.SetOutput(os.Stdout) stats, err := lib.InitStats(statsPrefix) if err != nil { log.Fatalln("Failed to setup statter", err) } scoopConnection, err := loadclient.NewScoopLoader(scoopURL, manifestBucketPrefix, stats) if err != nil { log.Fatalln("Failed to setup scoop client for postgres", err) } pgBackend, err := metadata.NewPostgresLoader(&pgConfig, scoopConnection) if err != nil { log.Fatalln("Failed to setup postgres backend", err) } _, err = StartWorkers(pgBackend, stats) if err != nil { log.Fatalln("Failed to start workers", err) } hcBackend := healthcheck.BuildHealthCheckBackend(scoopConnection, pgBackend) hcHandler := healthcheck.BuildHealthCheckHandler(hcBackend) hcServeMux := http.NewServeMux() hcServeMux.Handle("/health", healthcheck.MakeHealthRouter(hcHandler)) go func() { if err := http.ListenAndServe(net.JoinHostPort("localhost", "8080"), hcServeMux); err != nil { log.Fatal("Health Check (HTTP) failed: ", err) } }() wait := make(chan struct{}) sigc := make(chan os.Signal, 1) signal.Notify(sigc, syscall.SIGINT) log.Println("Loader is set up") go func() { <-sigc log.Println("Sigint received -- shutting down") pgBackend.Close() // Cause flush stats.Close() workerGroup.Wait() close(wait) }() <-wait }