update agent

This commit is contained in:
2026-07-17 15:41:05 +07:00
parent 13bea66473
commit 476c41cf08
15 changed files with 467 additions and 20 deletions

View File

@@ -1,8 +1,9 @@
from __future__ import annotations
import time
from pathlib import Path
from app.core.command_runner import CommandRunner
from app.core.command_runner import CommandError, CommandRunner
APT_DPKG_OPTIONS = [
@@ -101,3 +102,42 @@ class DebInstaller:
return True
except Exception:
return False
class AptInstaller(DebInstaller):
def update_package_index(self) -> None:
self.command_runner.run(
["apt-get", "update"],
timeout=600,
env=APT_NONINTERACTIVE_ENV,
)
def install_package(self, package_name: str) -> None:
self.command_runner.run(
[
"apt-get",
*APT_DPKG_OPTIONS,
"install",
"--yes",
package_name,
],
timeout=1200,
env=APT_NONINTERACTIVE_ENV,
)
def wait_for_postgresql(
self,
attempts: int = 6,
delay_seconds: float = 2.0,
) -> None:
last_error: CommandError | None = None
for attempt in range(1, attempts + 1):
try:
self.command_runner.run(["pg_isready", "--timeout=5"], timeout=10)
return
except CommandError as error:
last_error = error
if attempt < attempts:
time.sleep(delay_seconds)
raise RuntimeError("PostgreSQL did not become ready after installation") from last_error