39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import paramiko
|
|
|
|
HOST = "2.26.123.84"
|
|
USER = "root"
|
|
PASSWORD = os.environ["VPS_PASSWORD"]
|
|
|
|
commands = [
|
|
"cd /root/iaai-parser && docker compose ps",
|
|
"cd /root/iaai-parser && docker compose exec -T worker celery -A iaai_scraper.worker.celery_app inspect active reserved scheduled",
|
|
"docker exec -i iaai-postgres psql -U iaai -d iaai_scraper -c \"SELECT now() AS ts, (SELECT count(*) FROM iaai_cars) AS cars, (SELECT count(*) FROM iaai_sync_runs) AS runs, (SELECT status FROM iaai_sync_runs ORDER BY id DESC LIMIT 1) AS last_status, (SELECT cars_upserted FROM iaai_sync_runs ORDER BY id DESC LIMIT 1) AS last_upserted, (SELECT cars_failed FROM iaai_sync_runs ORDER BY id DESC LIMIT 1) AS last_failed, (SELECT started_at FROM iaai_sync_runs ORDER BY id DESC LIMIT 1) AS last_started;\"",
|
|
"docker logs --since 10m iaai-parser-worker-1 2>&1 | tail -n 160",
|
|
]
|
|
|
|
client = paramiko.SSHClient()
|
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
client.connect(
|
|
HOST,
|
|
username=USER,
|
|
password=PASSWORD,
|
|
look_for_keys=False,
|
|
allow_agent=False,
|
|
timeout=30,
|
|
banner_timeout=30,
|
|
auth_timeout=30,
|
|
)
|
|
try:
|
|
for command in commands:
|
|
print(f"\n=== REMOTE_RUN {command} ===", flush=True)
|
|
stdin, stdout, stderr = client.exec_command(command, timeout=180)
|
|
exit_code = stdout.channel.recv_exit_status()
|
|
print(stdout.read().decode("utf-8", "replace"), end="")
|
|
print(stderr.read().decode("utf-8", "replace"), end="")
|
|
print(f"\n=== EXIT {exit_code} ===", flush=True)
|
|
finally:
|
|
client.close()
|