gitea user and pswd, some pages removed, logs
This commit is contained in:
@@ -434,6 +434,79 @@ def get_job_logs_after(job_id: int, last_log_id: int = 0, limit: int = 100):
|
||||
return [dict(row) for row in rows]
|
||||
|
||||
|
||||
def _job_log_filters(query: str | None, stream: str | None, job_id: int | None) -> tuple[str, list[Any]]:
|
||||
filters = []
|
||||
params: list[Any] = []
|
||||
if query:
|
||||
filters.append("l.message LIKE ?")
|
||||
params.append(f"%{query}%")
|
||||
if stream:
|
||||
filters.append("l.stream = ?")
|
||||
params.append(stream)
|
||||
if job_id:
|
||||
filters.append("l.job_id = ?")
|
||||
params.append(job_id)
|
||||
where_sql = f"WHERE {' AND '.join(filters)}" if filters else ""
|
||||
return where_sql, params
|
||||
|
||||
|
||||
def search_job_logs(
|
||||
query: str | None = None,
|
||||
stream: str | None = None,
|
||||
job_id: int | None = None,
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
):
|
||||
"""Globální prohlížeč logů: hledá řádky napříč všemi úlohami a vrací je i s kontextem úlohy
|
||||
(typ, cíl, stav) seřazené od nejnovějších, aby se šlo proklikat na konkrétní řádek úlohy."""
|
||||
run_migrations()
|
||||
con = get_connection()
|
||||
where_sql, params = _job_log_filters(query, stream, job_id)
|
||||
rows = con.execute(
|
||||
f"""
|
||||
SELECT
|
||||
l.id,
|
||||
l.job_id,
|
||||
l.stream,
|
||||
l.message,
|
||||
l.created_at,
|
||||
j.type AS job_type,
|
||||
j.target_type AS target_type,
|
||||
j.target_id AS target_id,
|
||||
j.status AS job_status
|
||||
FROM job_logs l
|
||||
JOIN jobs j ON j.id = l.job_id
|
||||
{where_sql}
|
||||
ORDER BY l.id DESC
|
||||
LIMIT ? OFFSET ?
|
||||
""",
|
||||
(*params, limit, offset),
|
||||
).fetchall()
|
||||
con.close()
|
||||
return [dict(row) for row in rows]
|
||||
|
||||
|
||||
def count_job_logs(
|
||||
query: str | None = None,
|
||||
stream: str | None = None,
|
||||
job_id: int | None = None,
|
||||
) -> int:
|
||||
run_migrations()
|
||||
con = get_connection()
|
||||
where_sql, params = _job_log_filters(query, stream, job_id)
|
||||
row = con.execute(
|
||||
f"""
|
||||
SELECT COUNT(*) AS count
|
||||
FROM job_logs l
|
||||
JOIN jobs j ON j.id = l.job_id
|
||||
{where_sql}
|
||||
""",
|
||||
params,
|
||||
).fetchone()
|
||||
con.close()
|
||||
return int(row["count"] or 0) if row else 0
|
||||
|
||||
|
||||
def has_active_deploy_job(target_type: str, target_id: str):
|
||||
run_migrations()
|
||||
con = get_connection()
|
||||
|
||||
Reference in New Issue
Block a user