add basic leader election on top of postgres
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-01-06 23:19:03 +01:00
parent 43685291b6
commit f2ef496b82
10 changed files with 114 additions and 7 deletions

View File

@@ -21,5 +21,5 @@ func (a *App) Logger() *slog.Logger {
}
func (a *App) Scheduler() *scheduler.Scheduler {
return scheduler.NewScheduler(a.logger)
return scheduler.NewScheduler(a.logger, Postgres())
}

23
internal/app/postgres.go Normal file
View File

@@ -0,0 +1,23 @@
package app
import (
"context"
"fmt"
"os"
"time"
"git.front.kjuulh.io/kjuulh/orbis/internal/utilities"
"github.com/jackc/pgx/v5"
)
var Postgres = utilities.Singleton(func() (*pgx.Conn, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
conn, err := pgx.Connect(ctx, os.Getenv("ORBIS_POSTGRES_DB"))
if err != nil {
return nil, fmt.Errorf("failed to connect to orbis postgres database: %w", err)
}
return conn, nil
})