sarafu-vise-events/cmd/main.go

66 lines
1.7 KiB
Go
Raw Normal View History

2024-10-23 22:01:10 +02:00
package main
import (
"context"
"flag"
2024-10-23 22:01:10 +02:00
"fmt"
"os"
"os/signal"
"syscall"
2025-01-13 09:28:29 +01:00
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event/nats"
2025-01-13 18:47:21 +01:00
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
2025-01-21 16:33:29 +01:00
"git.grassecon.net/grassrootseconomics/visedriver/storage"
2024-10-23 22:01:10 +02:00
)
2025-01-13 09:28:29 +01:00
var (
2025-01-21 16:33:29 +01:00
logg = logging.NewVanilla()
2025-01-13 09:28:29 +01:00
)
2024-10-23 22:01:10 +02:00
func main() {
config.LoadConfig()
override := config.NewOverride()
2024-12-05 16:17:36 +01:00
flag.StringVar(override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
flag.StringVar(override.ResourceConn, "resource", "?", "resource connection string")
flag.StringVar(override.UserConn, "userdata", "?", "userdata store connection string")
flag.StringVar(override.StateConn, "state", "?", "state store connection string")
flag.Parse()
config.Apply(&override)
conns, err := config.GetConns()
if err != nil {
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
os.Exit(1)
}
logg.Infof("start command", "conn", conns)
2025-01-13 09:28:29 +01:00
ctx := context.Background()
menuStorageService := storage.NewMenuStorageService(conns)
eu := viseevent.NewEventsUpdater(lookup.Api, menuStorageService)
eh := eu.ToEventsHandler()
n := nats.NewNatsSubscription(eh)
err = n.Connect(ctx, config.JetstreamURL)
2024-10-23 22:01:10 +02:00
if err != nil {
fmt.Fprintf(os.Stderr, "Stream connect err: %v", err)
2024-10-23 22:01:10 +02:00
os.Exit(1)
}
defer n.Close()
cint := make(chan os.Signal)
cterm := make(chan os.Signal)
signal.Notify(cint, os.Interrupt, syscall.SIGINT)
signal.Notify(cterm, os.Interrupt, syscall.SIGTERM)
select {
case _ = <-cint:
case _ = <-cterm:
}
}