- Archive completed subtask files (PLAN, CODE_REVIEW, logs) to agent-task/archive - Add postgres_internal_test.go for internal storage tests - Update worker main.go, runtime, storage, and runner with iop agent run bridge - Expand test coverage in runtime_test.go, postgres_test.go, storage_test.go, runner_test.go - Update gito-control-plane notes and roadmap milestone
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"git.toki-labs.com/toki/gito/services/core/internal/config"
|
|
"git.toki-labs.com/toki/gito/services/core/internal/controlplane"
|
|
"git.toki-labs.com/toki/gito/services/core/internal/storage"
|
|
"git.toki-labs.com/toki/gito/services/core/internal/worker"
|
|
)
|
|
|
|
// migrationSQL loads the initial migration SQL from well-known paths relative
|
|
// to the executable or common working directories, so the server/worker works
|
|
// regardless of the cwd it is launched from.
|
|
func migrationSQL() string {
|
|
exe, err := os.Executable()
|
|
if err != nil {
|
|
exe = ""
|
|
}
|
|
candidates := []string{
|
|
// set explicitly via env
|
|
os.Getenv("GITO_MIGRATION_PATH"),
|
|
// next to the binary (bin/gito-server → bin/../migrations/...)
|
|
filepath.Join(filepath.Dir(exe), "migrations", "00001_initial.sql"),
|
|
// launched from repo root
|
|
filepath.Join("services", "core", "migrations", "00001_initial.sql"),
|
|
// launched from services/core
|
|
filepath.Join("migrations", "00001_initial.sql"),
|
|
}
|
|
for _, p := range candidates {
|
|
if p == "" {
|
|
continue
|
|
}
|
|
data, err := os.ReadFile(p)
|
|
if err == nil {
|
|
return string(data)
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func main() {
|
|
cfg := config.Load()
|
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
|
|
|
var scanner worker.RevisionScanner
|
|
if dsn := os.Getenv("DATABASE_URL"); dsn != "" {
|
|
pgStore, err := storage.NewPgStore(context.Background(), dsn, migrationSQL())
|
|
if err != nil {
|
|
logger.Error("failed to open postgres store", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
logger.Info("postgres store connected")
|
|
defer pgStore.Close()
|
|
publisher := controlplane.NewOutboxBroadcaster(pgStore.OperationEvents())
|
|
scanner = controlplane.NewRuntimeWithStore(publisher, pgStore)
|
|
}
|
|
|
|
runner := worker.NewRunner(cfg, logger, nil, nil, scanner)
|
|
if err := runner.Run(); err != nil {
|
|
logger.Error("worker stopped", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|