feat(jobs): add stop button
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-07-17 00:50:07 +02:00
parent 53155d4e53
commit b39daba561
3 changed files with 49 additions and 6 deletions
@@ -22,6 +22,7 @@ from .model import (
JobRunLogs,
JobRunStatus,
JobTriggeredBy,
utcnow,
)
logger = logging.getLogger(__name__)
@@ -267,13 +268,26 @@ def stop_run(
status_code=status.HTTP_409_CONFLICT,
detail=f"Run {run_id} is not running.",
)
run.status = JobRunStatus.STOPPED
run.finished_at = utcnow()
session.add(run)
session.commit()
session.refresh(run)
try:
runner.get_docker_client().containers.get(run.container_id).stop()
except Exception as error: # noqa: BLE001
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to stop container: {error}",
)
container = runner.get_docker_client().containers.get(run.container_id)
container.stop()
container.reload()
run.logs = container.logs().decode("utf-8", errors="replace")
run.exit_code = container.attrs["State"]["ExitCode"]
container.remove()
session.add(run)
session.commit()
session.refresh(run)
except Exception: # noqa: BLE001
logger.warning("Cleanup after stopping run %s failed.", run_id, exc_info=True)
return run
@@ -115,6 +115,15 @@
(click)="runNow(row)">
<mat-icon>play_arrow</mat-icon>
</button>
<button
mat-icon-button
type="button"
aria-label="Stoppen"
matTooltip="Stoppen"
[disabled]="row.status !== 'running'"
(click)="stopNow(row)">
<mat-icon>stop</mat-icon>
</button>
<button
mat-icon-button
type="button"
@@ -171,6 +171,26 @@ export class JobsComponent implements OnInit {
});
}
protected stopNow(task: BackgroundJobTask): void {
const runId = task.last_run?.id;
if (task.status !== 'running' || runId == null) return;
this.backgroundJobsService.stopBackgroundJobRun(runId).subscribe({
next: () => {
this.snackBar.open(`„${task.name}“ wird gestoppt.`, 'OK', {
duration: 3000,
});
this.pollWhileRunning();
},
error: (error) =>
this.showError(
error.status === 409
? `„${task.name}“ läuft nicht.`
: `„${task.name}“ konnte nicht gestoppt werden.`,
),
});
}
protected openLogsDialog(task: BackgroundJobTask): void {
if (task.last_run?.id == null) return;