36 lines
772 B
PHP
36 lines
772 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\OpsUx;
|
|
|
|
use App\Models\OperationRun;
|
|
|
|
final class RunDetailPolling
|
|
{
|
|
/**
|
|
* Returns a Livewire polling interval string (e.g. "1s") while the run is active.
|
|
* Returns null once the run is terminal.
|
|
*/
|
|
public static function interval(OperationRun $run): ?string
|
|
{
|
|
$uxStatus = OperationStatusNormalizer::toUxStatus($run->status, $run->outcome);
|
|
|
|
if (! in_array($uxStatus, ['queued', 'running'], true)) {
|
|
return null;
|
|
}
|
|
|
|
$ageSeconds = now()->diffInSeconds($run->created_at ?? now());
|
|
|
|
if ($ageSeconds < 10) {
|
|
return '1s';
|
|
}
|
|
|
|
if ($ageSeconds < 60) {
|
|
return '5s';
|
|
}
|
|
|
|
return '10s';
|
|
}
|
|
}
|