kontrola na jobs na nedoployovatelne repositare
This commit is contained in:
+19
-1
@@ -17,6 +17,7 @@ LIVE_STATUSES = {"queued", "running", "cancelled_requested"}
|
|||||||
JOB_STATUSES = {"queued", "running", "cancelled_requested", "cancelled", "success", "failed"}
|
JOB_STATUSES = {"queued", "running", "cancelled_requested", "cancelled", "success", "failed"}
|
||||||
JOB_FILTER_STATUSES = ("queued", "running", "success", "failed", "cancelled")
|
JOB_FILTER_STATUSES = ("queued", "running", "success", "failed", "cancelled")
|
||||||
JOB_FILTER_TYPES = ("deploy_app", "deploy_core_service")
|
JOB_FILTER_TYPES = ("deploy_app", "deploy_core_service")
|
||||||
|
IGNORED_RETRY_REPOSITORIES = {"appfactory-tools", "appfactory-infrastructure"}
|
||||||
|
|
||||||
|
|
||||||
def render_job_status(status: str | None) -> str:
|
def render_job_status(status: str | None) -> str:
|
||||||
@@ -56,6 +57,17 @@ def render_options(values: tuple[str, ...], selected: str, empty_label: str) ->
|
|||||||
return "".join(options)
|
return "".join(options)
|
||||||
|
|
||||||
|
|
||||||
|
def can_retry_job(job: dict) -> bool:
|
||||||
|
job_type = job.get("type") or ""
|
||||||
|
target_id = job.get("target_id") or ""
|
||||||
|
|
||||||
|
if job_type == "deploy_core_service":
|
||||||
|
return True
|
||||||
|
if job_type == "deploy_app" and target_id not in IGNORED_RETRY_REPOSITORIES:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@router.get("/jobs", response_class=HTMLResponse)
|
@router.get("/jobs", response_class=HTMLResponse)
|
||||||
def jobs_page(
|
def jobs_page(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -188,12 +200,15 @@ def job_detail_page(job_id: int, request: Request, user=Depends(require_user)):
|
|||||||
result = html.escape(pretty_json(job.get("result_json")))
|
result = html.escape(pretty_json(job.get("result_json")))
|
||||||
error_text = html.escape(job.get("error_text", "") or "")
|
error_text = html.escape(job.get("error_text", "") or "")
|
||||||
actions = ""
|
actions = ""
|
||||||
if status_value == "failed":
|
retry_blocked_notice = ""
|
||||||
|
if status_value == "failed" and can_retry_job(job):
|
||||||
actions += f"""
|
actions += f"""
|
||||||
<form method="post" action="/portal/jobs/{html.escape(str(job_id))}/retry" onsubmit="return confirm('Retry job #{html.escape(str(job_id))}?');">
|
<form method="post" action="/portal/jobs/{html.escape(str(job_id))}/retry" onsubmit="return confirm('Retry job #{html.escape(str(job_id))}?');">
|
||||||
<button type="submit">Retry Job</button>
|
<button type="submit">Retry Job</button>
|
||||||
</form>
|
</form>
|
||||||
"""
|
"""
|
||||||
|
elif status_value == "failed" and (job.get("target_id") or "") in IGNORED_RETRY_REPOSITORIES:
|
||||||
|
retry_blocked_notice = '<p class="muted">Tento repozitář není deployovatelná služba.</p>'
|
||||||
if status_value in {"queued", "running"}:
|
if status_value in {"queued", "running"}:
|
||||||
actions += f"""
|
actions += f"""
|
||||||
<form method="post" action="/portal/jobs/{html.escape(str(job_id))}/cancel" onsubmit="return confirm('Cancel job #{html.escape(str(job_id))}?');">
|
<form method="post" action="/portal/jobs/{html.escape(str(job_id))}/cancel" onsubmit="return confirm('Cancel job #{html.escape(str(job_id))}?');">
|
||||||
@@ -233,6 +248,7 @@ def job_detail_page(job_id: int, request: Request, user=Depends(require_user)):
|
|||||||
<a class="btn" href="/portal/jobs">← Zpět na joby</a>
|
<a class="btn" href="/portal/jobs">← Zpět na joby</a>
|
||||||
<a class="btn btn-secondary" href="{target_url}">Detail targetu</a>
|
<a class="btn btn-secondary" href="{target_url}">Detail targetu</a>
|
||||||
</p>
|
</p>
|
||||||
|
{retry_blocked_notice}
|
||||||
{actions}
|
{actions}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -280,6 +296,8 @@ def retry_job_action(job_id: int, user=Depends(require_user)):
|
|||||||
raise HTTPException(status_code=404, detail="Job not found")
|
raise HTTPException(status_code=404, detail="Job not found")
|
||||||
if (job.get("status") or "").lower() != "failed":
|
if (job.get("status") or "").lower() != "failed":
|
||||||
raise HTTPException(status_code=400, detail="Only failed jobs can be retried")
|
raise HTTPException(status_code=400, detail="Only failed jobs can be retried")
|
||||||
|
if not can_retry_job(job):
|
||||||
|
raise HTTPException(status_code=400, detail="This job cannot be retried")
|
||||||
|
|
||||||
new_job_id = retry_failed_job(job_id, user)
|
new_job_id = retry_failed_job(job_id, user)
|
||||||
if not new_job_id:
|
if not new_job_id:
|
||||||
|
|||||||
Reference in New Issue
Block a user