Backup #673
| ID | 673 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/UseCases/Pipeline/PipelineRunStatusUseCase.php |
| Version | 2 |
| Typ |
modified |
| Größe | 3.3 KB |
| Hash | 7973d473eb88279b47b65fb437574ae129f27736fd1e41f42e804e07e602793e |
| Datum | 2025-12-23 05:10:31 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace UseCases\Pipeline;
use Infrastructure\Persistence\PipelineRepository;
/**
* PipelineRunStatusUseCase - Get detailed pipeline run status.
*
* Calculates progress, elapsed time, ETA, and detects stalled runs.
*/
class PipelineRunStatusUseCase
{
private PipelineRepository $repository;
public function __construct(?PipelineRepository $repository = null)
{
$this->repository = $repository ?? new PipelineRepository();
}
/**
* Get detailed run status with progress calculations.
*
* @param int $pipelineId Pipeline ID
* @param int $runId Run ID
* @return array{success: bool, error?: string, data?: array}
*/
public function execute(int $pipelineId, int $runId): array
{
$run = $this->repository->findRunById($runId);
if ($run === null || (int) $run['pipeline_id'] !== $pipelineId) {
return ['success' => false, 'error' => 'Run nicht gefunden'];
}
return [
'success' => true,
'data' => $this->buildStatusData($run),
];
}
/**
* Build comprehensive status data from run record.
*/
private function buildStatusData(array $run): array
{
$startedAt = strtotime($run['started_at'] ?? 'now');
$elapsed = time() - $startedAt;
$total = (int) ($run['documents_total'] ?? 0);
$processed = (int) ($run['documents_processed'] ?? 0);
$progress = $total > 0 ? min(100, round(($processed / $total) * 100)) : 0;
// Cap processed display to not exceed total
$processedDisplay = min($processed, $total);
$estimatedRemaining = $this->calculateEta($elapsed, $processed, $total);
$lastUpdate = strtotime($run['last_update_at'] ?? $run['started_at'] ?? 'now');
$isStalled = (time() - $lastUpdate) > 60 && $run['status'] === 'running';
$isTerminal = in_array($run['status'], ['completed', 'failed', 'cancelled'], true);
return [
'status' => $run['status'],
'current_step' => $run['current_step'],
'current_document' => $run['current_document'],
'documents_total' => $total,
'documents_processed' => $processed,
'documents_failed' => (int) ($run['documents_failed'] ?? 0),
'chunks_created' => (int) ($run['chunks_created'] ?? 0),
'embeddings_created' => (int) ($run['embeddings_created'] ?? 0),
'progress' => $progress,
'elapsed' => $elapsed,
'elapsed_formatted' => gmdate('i:s', $elapsed),
'estimated_remaining' => $estimatedRemaining,
'estimated_formatted' => $estimatedRemaining !== null ? gmdate('i:s', $estimatedRemaining) : null,
'log_tail' => $run['log_tail'] ?? '',
'is_stalled' => $isStalled,
'is_terminal' => $isTerminal,
'completed_at' => $run['completed_at'],
'error_log' => $run['error_log'],
];
}
/**
* Calculate estimated time remaining.
*/
private function calculateEta(int $elapsed, int $processed, int $total): ?int
{
if ($processed <= 0 || $total <= $processed) {
return null;
}
$avgTimePerDoc = $elapsed / $processed;
$remaining = $total - $processed;
return (int) ($avgTimePerDoc * $remaining);
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1823 |
7 |
modified |
3.2 KB |
2025-12-27 23:15 |
| 1822 |
6 |
modified |
3.2 KB |
2025-12-27 23:15 |
| 1821 |
5 |
modified |
3.2 KB |
2025-12-27 23:15 |
| 835 |
4 |
modified |
3.3 KB |
2025-12-23 08:16 |
| 723 |
3 |
modified |
3.3 KB |
2025-12-23 07:56 |
| 673 |
2 |
modified |
3.3 KB |
2025-12-23 05:10 |
| 672 |
1 |
modified |
3.2 KB |
2025-12-23 05:10 |
← Zurück zur Übersicht