fix: use dedicated connection for scheduler process
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2025-01-17 21:30:56 +01:00
parent e94271d5e2
commit 54aa310583
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM

View File

@ -67,8 +67,13 @@ func (s *Scheduler) acquireLeader(ctx context.Context) (bool, error) {
case <-ctx.Done():
return false, nil
default:
db, err := s.db.Acquire(ctx)
if err != nil {
return false, fmt.Errorf("failed to acquire db connection: %w", err)
}
var acquiredLock bool
if err := s.db.QueryRow(ctx, "SELECT pg_try_advisory_lock(1234)").Scan(&acquiredLock); err != nil {
if err := db.QueryRow(ctx, "SELECT pg_try_advisory_lock(1234)").Scan(&acquiredLock); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return false, nil
}