feat(jobs): show run duration and live elapsed time
This commit is contained in:
@@ -25,6 +25,9 @@
|
||||
@if (run.exit_code != null) {
|
||||
· Exit {{ run.exit_code }}
|
||||
}
|
||||
@if (formatRunDuration(run); as dur) {
|
||||
· {{ dur }}
|
||||
}
|
||||
</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
@@ -41,6 +44,15 @@
|
||||
{{ statusMeta(runStatus()!).label }}
|
||||
</span>
|
||||
}
|
||||
@if (selectedRun(); as run) {
|
||||
@if (runStatus() === 'running' || runStatus() === 'stopping') {
|
||||
@if (formatRunElapsed(run, nowMs()); as elapsed) {
|
||||
<span class="run-duration">läuft seit {{ elapsed }}</span>
|
||||
}
|
||||
} @else if (formatRunDuration(run); as dur) {
|
||||
<span class="run-duration">Dauer: {{ dur }}</span>
|
||||
}
|
||||
}
|
||||
<span class="logs-hint">zeigt letzte 200 Zeilen</span>
|
||||
</div>
|
||||
<div class="logs-actions">
|
||||
|
||||
@@ -138,6 +138,11 @@
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.run-duration {
|
||||
font-size: 13px;
|
||||
color: #475569;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.logs-header {
|
||||
flex-direction: column;
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
DestroyRef,
|
||||
ElementRef,
|
||||
OnInit,
|
||||
computed,
|
||||
inject,
|
||||
signal,
|
||||
viewChild,
|
||||
@@ -22,7 +23,12 @@ import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { finalize, timer } from 'rxjs';
|
||||
import { BackgroundJobsService, BackgroundJobTask, JobRun } from '../../../api';
|
||||
import { formatUtcDateAsLocal, statusMeta } from '../jobs.utils';
|
||||
import {
|
||||
formatRunDuration,
|
||||
formatRunElapsed,
|
||||
formatUtcDateAsLocal,
|
||||
statusMeta,
|
||||
} from '../jobs.utils';
|
||||
|
||||
export interface JobLogsDialogData {
|
||||
task: BackgroundJobTask;
|
||||
@@ -52,6 +58,8 @@ export class JobLogsDialogComponent implements OnInit {
|
||||
|
||||
protected readonly statusMeta = statusMeta;
|
||||
protected readonly formatUtcDateAsLocal = formatUtcDateAsLocal;
|
||||
protected readonly formatRunDuration = formatRunDuration;
|
||||
protected readonly formatRunElapsed = formatRunElapsed;
|
||||
|
||||
protected readonly runs = signal<JobRun[]>([]);
|
||||
protected readonly runsLoading = signal(false);
|
||||
@@ -60,6 +68,11 @@ export class JobLogsDialogComponent implements OnInit {
|
||||
protected readonly loading = signal(false);
|
||||
protected readonly logs = signal<string>('');
|
||||
protected readonly runStatus = signal<string | null>(null);
|
||||
protected readonly nowMs = signal(Date.now());
|
||||
|
||||
protected readonly selectedRun = computed(
|
||||
() => this.runs().find((run) => run.id === this.selectedRunId()) ?? null,
|
||||
);
|
||||
|
||||
private readonly logsPanel = viewChild<ElementRef<HTMLElement>>('logsPanel');
|
||||
|
||||
@@ -74,6 +87,10 @@ export class JobLogsDialogComponent implements OnInit {
|
||||
timer(5000, 5000)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(() => this.loadRuns());
|
||||
// Ticks the live "läuft seit …" duration every second.
|
||||
timer(1000, 1000)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(() => this.nowMs.set(Date.now()));
|
||||
}
|
||||
|
||||
protected loadRuns(selectLatest = false): void {
|
||||
|
||||
@@ -108,6 +108,13 @@
|
||||
@if (row.last_run) {
|
||||
<div class="last-run-cell">
|
||||
<span>{{ formatUtcDateAsLocal(row.last_run.started_at) }}</span>
|
||||
@if (row.status === 'running' || row.status === 'stopping') {
|
||||
@if (formatRunElapsed(row.last_run, nowMs()); as elapsed) {
|
||||
<span class="last-run-message">läuft seit {{ elapsed }}</span>
|
||||
}
|
||||
} @else if (formatRunDuration(row.last_run); as duration) {
|
||||
<span class="last-run-message">Dauer: {{ duration }}</span>
|
||||
}
|
||||
@if (row.last_run.exit_code != null) {
|
||||
<span class="last-run-message"
|
||||
>Exit-Code {{ row.last_run.exit_code }}</span
|
||||
|
||||
@@ -28,6 +28,8 @@ import {
|
||||
GenericColumn,
|
||||
} from '../../shared/ui/data-table/data-table.component';
|
||||
import {
|
||||
formatRunDuration,
|
||||
formatRunElapsed,
|
||||
formatScheduleCron,
|
||||
formatUtcDateAsLocal,
|
||||
statusMeta,
|
||||
@@ -77,10 +79,13 @@ export class JobsComponent implements OnInit {
|
||||
protected readonly dockerHealth = signal<DockerHealth | null>(null);
|
||||
protected readonly dockerHealthLoading = signal(false);
|
||||
protected readonly deletingTaskIds = signal<ReadonlySet<number>>(new Set());
|
||||
protected readonly nowMs = signal(Date.now());
|
||||
|
||||
protected readonly statusMeta = statusMeta;
|
||||
protected readonly formatScheduleCron = formatScheduleCron;
|
||||
protected readonly formatUtcDateAsLocal = formatUtcDateAsLocal;
|
||||
protected readonly formatRunDuration = formatRunDuration;
|
||||
protected readonly formatRunElapsed = formatRunElapsed;
|
||||
|
||||
protected taskColumns: GenericColumn<BackgroundJobTask>[] = [];
|
||||
|
||||
@@ -123,6 +128,11 @@ export class JobsComponent implements OnInit {
|
||||
)
|
||||
.subscribe((tasks) => this.setTasksPreservingPendingStops(tasks));
|
||||
|
||||
// Ticks the live "läuft seit …" duration in the last-run column.
|
||||
timer(1000, 1000)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(() => this.nowMs.set(Date.now()));
|
||||
|
||||
this.taskColumns = [
|
||||
{
|
||||
id: 'name',
|
||||
|
||||
@@ -39,9 +39,18 @@ export function formatScheduleCron(schedule: string | null): string {
|
||||
return schedule ? `Cron: ${schedule}` : 'Nur manuell';
|
||||
}
|
||||
|
||||
// Backend timestamps are naive UTC without a timezone suffix, so add a "Z"
|
||||
// before parsing to keep them comparable with the (UTC-based) wall clock.
|
||||
function appendUtcZ(value: string): string {
|
||||
return /(?:Z|[+-]\d{2}:\d{2})$/.test(value) ? value : `${value}Z`;
|
||||
}
|
||||
|
||||
function toUtcMs(value: string): number {
|
||||
return new Date(appendUtcZ(value)).getTime();
|
||||
}
|
||||
|
||||
export function formatUtcDateAsLocal(value: string | null | undefined): string {
|
||||
if (!value) return '';
|
||||
const utcValue = /(?:Z|[+-]\d{2}:\d{2})$/.test(value) ? value : `${value}Z`;
|
||||
return new Intl.DateTimeFormat('de-DE', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
@@ -49,18 +58,32 @@ export function formatUtcDateAsLocal(value: string | null | undefined): string {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
}).format(new Date(utcValue));
|
||||
}).format(new Date(appendUtcZ(value)));
|
||||
}
|
||||
|
||||
// Compact clock format: "00:05 min", "02:28 min", and "1:01:30 h" past an hour.
|
||||
export function formatDurationSeconds(totalSeconds: number): string {
|
||||
const s = Math.max(0, Math.round(totalSeconds));
|
||||
const pad = (n: number) => n.toString().padStart(2, '0');
|
||||
const hours = Math.floor(s / 3600);
|
||||
const minutes = Math.floor((s % 3600) / 60);
|
||||
const seconds = s % 60;
|
||||
if (hours > 0) {
|
||||
return `${hours}:${pad(minutes)}:${pad(seconds)} h`;
|
||||
}
|
||||
return `${pad(minutes)}:${pad(seconds)} min`;
|
||||
}
|
||||
|
||||
// Duration of a finished run, or null while it is still running.
|
||||
export function formatRunDuration(run: JobRun): string | null {
|
||||
if (!run.started_at || !run.finished_at) return null;
|
||||
const seconds = Math.max(
|
||||
0,
|
||||
Math.round(
|
||||
(new Date(run.finished_at).getTime() -
|
||||
new Date(run.started_at).getTime()) /
|
||||
1000,
|
||||
),
|
||||
return formatDurationSeconds(
|
||||
(toUtcMs(run.finished_at) - toUtcMs(run.started_at)) / 1000,
|
||||
);
|
||||
return `${seconds} s`;
|
||||
}
|
||||
|
||||
// Live elapsed time since the run started, relative to the given "now" (ms).
|
||||
export function formatRunElapsed(run: JobRun, nowMs: number): string | null {
|
||||
if (!run.started_at) return null;
|
||||
return formatDurationSeconds((nowMs - toUtcMs(run.started_at)) / 1000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user