filtry v jobs a shrnuti

This commit is contained in:
JiriUhlir
2026-05-29 09:23:36 +02:00
parent f651f7efd6
commit 4b4bf55696
2 changed files with 99 additions and 7 deletions
+43 -3
View File
@@ -246,14 +246,34 @@ def get_next_queued_job():
return dict(row) if row else None
def get_jobs(limit: int = 100):
def get_jobs(
limit: int = 100,
status: str | None = None,
job_type: str | None = None,
target: str | None = None,
):
run_migrations()
con = get_connection()
filters = []
params: list[Any] = []
if status:
filters.append("status = ?")
params.append(status)
if job_type:
filters.append("type = ?")
params.append(job_type)
if target:
filters.append("(target_type LIKE ? OR target_id LIKE ?)")
target_pattern = f"%{target}%"
params.extend([target_pattern, target_pattern])
where_sql = f"WHERE {' AND '.join(filters)}" if filters else ""
rows = con.execute(
"""
f"""
SELECT *
FROM jobs
{where_sql}
ORDER BY
CASE
WHEN status = 'running' THEN 0
@@ -263,13 +283,33 @@ def get_jobs(limit: int = 100):
id DESC
LIMIT ?
""",
(limit,),
(*params, limit),
).fetchall()
con.close()
return [dict(row) for row in rows]
def get_job_stats():
run_migrations()
con = get_connection()
rows = con.execute(
"""
SELECT status, COUNT(*) AS count
FROM jobs
WHERE status IN ('queued', 'running', 'failed', 'success')
GROUP BY status
"""
).fetchall()
con.close()
stats = {"queued": 0, "running": 0, "failed": 0, "success": 0}
for row in rows:
stats[row["status"]] = row["count"]
return stats
def get_job(job_id: int):
run_migrations()
con = get_connection()