forked from mtusi2026/mtusi2026lab5
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab5/internal/config"
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab5/internal/store/postgres"
|
|
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
// run dispatches the server command or the container healthcheck.
|
|
func run(args []string) error {
|
|
if len(args) == 1 && args[0] == "worker" {
|
|
fx.New(workerApp()).Run()
|
|
return nil
|
|
}
|
|
if len(args) == 3 && args[0] == "replay" {
|
|
return replayJob(args[1], args[2])
|
|
}
|
|
if len(args) == 1 && args[0] == "s3-bootstrap" {
|
|
return bootstrapS3()
|
|
}
|
|
if len(args) == 0 {
|
|
fx.New(CreateApp()).Run()
|
|
return nil
|
|
}
|
|
if len(args) == 1 && args[0] == "reconcile" {
|
|
return reconcile(false)
|
|
}
|
|
if len(args) == 2 && args[0] == "reconcile" && args[1] == "--apply" {
|
|
return reconcile(true)
|
|
}
|
|
if len(args) == 1 && args[0] == "migrate" {
|
|
return migrate()
|
|
}
|
|
if len(args) == 1 && args[0] == "healthcheck" {
|
|
return healthcheck()
|
|
}
|
|
return fmt.Errorf("usage: server [healthcheck|migrate]")
|
|
}
|
|
|
|
// migrate applies versioned DDL once from an operator job, independently of the API.
|
|
func migrate() error {
|
|
cfg, err := config.NewPersistence()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
database, err := postgres.New(postgres.Options{URL: cfg.DatabaseURL, MaxConnections: 1, Timeout: 30 * time.Second})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer database.Close()
|
|
return database.Start(context.Background())
|
|
}
|