Реализовать PostgreSQL, Redis-сессии и backup-трек для сдачи lab2 на 5.
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def compose(*args, check=True, input_bytes=None, timeout=180):
|
||||
proc = subprocess.run(
|
||||
["docker", "compose", "--env-file", ".env", *args],
|
||||
cwd=ROOT,
|
||||
input=input_bytes,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
timeout=timeout,
|
||||
check=False,
|
||||
)
|
||||
if check and proc.returncode != 0:
|
||||
err = proc.stderr.decode("utf-8", "replace")[-800:]
|
||||
raise RuntimeError(err or "docker compose failed")
|
||||
return proc
|
||||
|
||||
|
||||
def psql(sql, timeout=180):
|
||||
proc = compose(
|
||||
"exec",
|
||||
"-T",
|
||||
"postgres",
|
||||
"psql",
|
||||
"-U",
|
||||
"messenger",
|
||||
"-d",
|
||||
"messenger",
|
||||
"-v",
|
||||
"ON_ERROR_STOP=1",
|
||||
"-q",
|
||||
"-t",
|
||||
"-A",
|
||||
input_bytes=sql.encode("utf-8"),
|
||||
timeout=timeout,
|
||||
)
|
||||
return proc.stdout.decode("utf-8").strip()
|
||||
|
||||
|
||||
def psql_file(sql, timeout=180):
|
||||
"""Текст плана, без -t, чтобы EXPLAIN остался читаемым."""
|
||||
proc = compose(
|
||||
"exec",
|
||||
"-T",
|
||||
"postgres",
|
||||
"psql",
|
||||
"-U",
|
||||
"messenger",
|
||||
"-d",
|
||||
"messenger",
|
||||
"-v",
|
||||
"ON_ERROR_STOP=1",
|
||||
"-X",
|
||||
input_bytes=sql.encode("utf-8"),
|
||||
timeout=timeout,
|
||||
)
|
||||
return proc.stdout.decode("utf-8")
|
||||
Reference in New Issue
Block a user