fixes and improvements
This commit is contained in:
@@ -64,6 +64,18 @@ class MonitoringPoller:
|
||||
self._thread.start()
|
||||
logger.info("Monitoring poller started")
|
||||
|
||||
def kick(self) -> None:
|
||||
"""Run one immediate snapshot cycle in the background."""
|
||||
store = get_settings_store()
|
||||
config = self._config()
|
||||
threading.Thread(
|
||||
target=self._run_cycle,
|
||||
args=(store, config),
|
||||
name="monitoring-poller-kick",
|
||||
daemon=True,
|
||||
).start()
|
||||
logger.info("Monitoring poller kick requested")
|
||||
|
||||
def stop(self, timeout: float = 5.0) -> None:
|
||||
"""Stop the worker thread and wait briefly for shutdown."""
|
||||
with self._lock:
|
||||
|
||||
@@ -79,12 +79,21 @@ class SettingsStore:
|
||||
name TEXT NOT NULL,
|
||||
private_key TEXT NOT NULL,
|
||||
passphrase TEXT NOT NULL,
|
||||
public_key TEXT NOT NULL DEFAULT '',
|
||||
fingerprint TEXT NOT NULL DEFAULT '',
|
||||
notes TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
)
|
||||
"""
|
||||
)
|
||||
existing_key_columns = {
|
||||
row[1] for row in conn.execute("PRAGMA table_info(ssh_keys)").fetchall()
|
||||
}
|
||||
if "public_key" not in existing_key_columns:
|
||||
conn.execute("ALTER TABLE ssh_keys ADD COLUMN public_key TEXT NOT NULL DEFAULT ''")
|
||||
if "fingerprint" not in existing_key_columns:
|
||||
conn.execute("ALTER TABLE ssh_keys ADD COLUMN fingerprint TEXT NOT NULL DEFAULT ''")
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS saved_tasks (
|
||||
@@ -486,13 +495,15 @@ class SettingsStore:
|
||||
|
||||
def _row_to_ssh_key(self, row: sqlite3.Row, usage_count: int = 0) -> dict[str, Any]:
|
||||
summary = self._private_key_summary(str(row["private_key"] or ""))
|
||||
public_key = str(row["public_key"] or summary["public_key"] or "")
|
||||
fingerprint = str(row["fingerprint"] or summary["fingerprint"] or "")
|
||||
return {
|
||||
"id": row["id"],
|
||||
"name": row["name"],
|
||||
"private_key_set": bool(row["private_key"]),
|
||||
"passphrase_set": bool(row["passphrase"]),
|
||||
"public_key": summary["public_key"],
|
||||
"fingerprint": summary["fingerprint"],
|
||||
"public_key": public_key,
|
||||
"fingerprint": fingerprint,
|
||||
"usage_count": usage_count,
|
||||
"notes": row["notes"],
|
||||
"created_at": row["created_at"],
|
||||
@@ -512,7 +523,10 @@ class SettingsStore:
|
||||
passphrase = (current or {}).get("passphrase", "")
|
||||
passphrase = str(passphrase or "")
|
||||
notes = str(payload.get("notes") if payload.get("notes") is not None else (current or {}).get("notes", "") or "").strip()
|
||||
return {"id": key_id, "name": name, "private_key": private_key, "passphrase": passphrase, "notes": notes}
|
||||
summary = self._private_key_summary(private_key)
|
||||
public_key = str(payload.get("public_key") if payload.get("public_key") is not None else (current or {}).get("public_key", "") or summary["public_key"] or "").strip()
|
||||
fingerprint = str(payload.get("fingerprint") if payload.get("fingerprint") is not None else (current or {}).get("fingerprint", "") or summary["fingerprint"] or "").strip()
|
||||
return {"id": key_id, "name": name, "private_key": private_key, "passphrase": passphrase, "public_key": public_key, "fingerprint": fingerprint, "notes": notes}
|
||||
|
||||
def list_ssh_keys(self) -> list[dict[str, Any]]:
|
||||
self.init_schema()
|
||||
@@ -535,7 +549,7 @@ class SettingsStore:
|
||||
if not row:
|
||||
return None
|
||||
summary = self._private_key_summary(str(row["private_key"] or ""))
|
||||
return {"id": row["id"], "name": row["name"], "private_key": row["private_key"], "passphrase": row["passphrase"], "notes": row["notes"], "public_key": summary["public_key"], "fingerprint": summary["fingerprint"]}
|
||||
return {"id": row["id"], "name": row["name"], "private_key": row["private_key"], "passphrase": row["passphrase"], "notes": row["notes"], "public_key": str(row["public_key"] or summary["public_key"] or ""), "fingerprint": str(row["fingerprint"] or summary["fingerprint"] or "")}
|
||||
|
||||
def upsert_ssh_key(self, payload: dict[str, Any], key_id: str | None = None) -> dict[str, Any]:
|
||||
self.init_schema()
|
||||
@@ -546,16 +560,18 @@ class SettingsStore:
|
||||
created_at = int(existing[0]) if existing else now
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO ssh_keys (id, name, private_key, passphrase, notes, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO ssh_keys (id, name, private_key, passphrase, public_key, fingerprint, notes, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
name = excluded.name,
|
||||
private_key = excluded.private_key,
|
||||
passphrase = excluded.passphrase,
|
||||
public_key = excluded.public_key,
|
||||
fingerprint = excluded.fingerprint,
|
||||
notes = excluded.notes,
|
||||
updated_at = excluded.updated_at
|
||||
""",
|
||||
(key["id"], key["name"], key["private_key"], key["passphrase"], key["notes"], created_at, now),
|
||||
(key["id"], key["name"], key["private_key"], key["passphrase"], key["public_key"], key["fingerprint"], key["notes"], created_at, now),
|
||||
)
|
||||
return self.get_ssh_key(key["id"]) or key
|
||||
|
||||
@@ -644,6 +660,46 @@ class SettingsStore:
|
||||
).fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
|
||||
def record_task_run(
|
||||
self,
|
||||
task: dict[str, Any],
|
||||
status: str,
|
||||
*,
|
||||
machine_id: str,
|
||||
machine_name: str,
|
||||
task_type: str,
|
||||
duration_ms: int,
|
||||
request_id: str = "",
|
||||
stdout_tail: str = "",
|
||||
stderr_tail: str = "",
|
||||
error: str = "",
|
||||
) -> None:
|
||||
self.init_schema()
|
||||
now = int(time.time())
|
||||
with self.connect() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO saved_task_runs
|
||||
(id, task_id, task_name, machine_id, machine_name, task_type, status, created_at, duration_ms, request_id, stdout_tail, stderr_tail, error)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
uuid.uuid4().hex,
|
||||
str(task.get("id") or ""),
|
||||
str(task.get("name") or ""),
|
||||
machine_id,
|
||||
machine_name,
|
||||
task_type,
|
||||
status,
|
||||
now,
|
||||
duration_ms,
|
||||
request_id,
|
||||
stdout_tail,
|
||||
stderr_tail,
|
||||
error,
|
||||
),
|
||||
)
|
||||
|
||||
def _row_to_shortcut(self, row: sqlite3.Row) -> dict[str, Any]:
|
||||
target = json.loads(row["target_json"] or "{}")
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user