filtry v jobs a shrnuti
This commit is contained in:
+43
-3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user