add basic leader election on top of postgres
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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
23
internal/app/postgres.go
Normal 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
|
||||
})
|
Reference in New Issue
Block a user