Реализовать lab3 на оценку 4: балансировка и отказ API

This commit is contained in:
Daria0w0
2026-10-23 17:14:32 +03:00
parent 0ab3a341aa
commit a67e7996ec
88 changed files with 5105 additions and 21 deletions
+41
View File
@@ -0,0 +1,41 @@
package main
import (
"context"
"errors"
"fmt"
"time"
"gitflic.ru/project/d-sotnikova5/mtusi2026lab1-fork/internal/store"
)
func checkDatabase() error {
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
defer cancel()
pool, err := store.OpenPostgres(ctx, envOrDefault(
"DATABASE_PASSWORD_FILE", "/run/secrets/postgres_password",
))
if err != nil {
return err
}
defer pool.Close()
queryCtx, queryCancel := context.WithTimeout(ctx, 3*time.Second)
defer queryCancel()
var applied bool
err = pool.QueryRow(queryCtx,
"SELECT EXISTS (SELECT 1 FROM schema_migrations WHERE version = $1)",
int64(1),
).Scan(&applied)
if err != nil {
return errors.New("cannot read schema_migrations; check database and migrations")
}
if !applied {
return errors.New("migration 000001 is not applied")
}
fmt.Println("PASS: PostgreSQL connection, migration 000001; pool max_conns=10")
return nil
}