Skip to content

Commit ce69d1f

Browse files
committed
Add readable config ints.
1 parent 486dce3 commit ce69d1f

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/View/Helper/QueueHelper.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,36 @@ protected function taskConfig(string $jobTask): array {
100100
return $this->taskConfig[$jobTask] ?? [];
101101
}
102102

103+
/**
104+
* Formats seconds into a human-readable string for large values.
105+
*
106+
* Returns the seconds with human-readable addition in brackets for values >= 3600 (1 hour).
107+
*
108+
* @param int $seconds
109+
*
110+
* @return string
111+
*/
112+
public function secondsToHumanReadable(int $seconds): string {
113+
if ($seconds < 3600) {
114+
return (string)$seconds;
115+
}
116+
117+
$parts = [];
118+
$days = (int)floor($seconds / 86400);
119+
$hours = (int)floor(($seconds % 86400) / 3600);
120+
$minutes = (int)floor(($seconds % 3600) / 60);
121+
122+
if ($days > 0) {
123+
$parts[] = $days . 'd';
124+
}
125+
if ($hours > 0) {
126+
$parts[] = $hours . 'h';
127+
}
128+
if ($minutes > 0) {
129+
$parts[] = $minutes . 'm';
130+
}
131+
132+
return $seconds . ' (' . implode(' ', $parts) . ')';
133+
}
134+
103135
}

templates/Admin/Queue/index.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@
206206
echo '<b>No configuration found</b>';
207207
}
208208

209+
$timeConfigKeys = [
210+
'workerLifetime',
211+
'workerPhpTimeout',
212+
'defaultRequeueTimeout',
213+
'cleanuptimeout',
214+
'sleeptime',
215+
'workermaxruntime',
216+
'workertimeout',
217+
'defaultworkertimeout',
218+
];
209219
foreach ($configurations as $key => $configuration) {
210220
echo '<li>';
211221
if (is_string($configuration) && is_dir($configuration)) {
@@ -215,6 +225,8 @@
215225
$configuration = $configuration ? 'true' : 'false';
216226
} elseif (is_array($configuration)) {
217227
$configuration = implode(', ', $configuration);
228+
} elseif (is_int($configuration) && in_array($key, $timeConfigKeys, true)) {
229+
$configuration = $this->Queue->secondsToHumanReadable($configuration);
218230
}
219231
echo h($key) . ': ' . h($configuration);
220232
echo '</li>';

tests/TestCase/View/Helper/QueueHelperTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,31 @@ public function testFailureStatus() {
111111
$this->assertSame('Aborted', $result);
112112
}
113113

114+
/**
115+
* @return void
116+
*/
117+
public function testSecondsToHumanReadable(): void {
118+
// Below threshold - no human readable addition
119+
$this->assertSame('60', $this->QueueHelper->secondsToHumanReadable(60));
120+
$this->assertSame('3599', $this->QueueHelper->secondsToHumanReadable(3599));
121+
122+
// Exactly 1 hour
123+
$this->assertSame('3600 (1h)', $this->QueueHelper->secondsToHumanReadable(3600));
124+
125+
// 1 hour 30 minutes
126+
$this->assertSame('5400 (1h 30m)', $this->QueueHelper->secondsToHumanReadable(5400));
127+
128+
// 2 hours
129+
$this->assertSame('7200 (2h)', $this->QueueHelper->secondsToHumanReadable(7200));
130+
131+
// 1 day
132+
$this->assertSame('86400 (1d)', $this->QueueHelper->secondsToHumanReadable(86400));
133+
134+
// 30 days (cleanuptimeout default)
135+
$this->assertSame('2592000 (30d)', $this->QueueHelper->secondsToHumanReadable(2592000));
136+
137+
// 1 day 2 hours 30 minutes
138+
$this->assertSame('95400 (1d 2h 30m)', $this->QueueHelper->secondsToHumanReadable(95400));
139+
}
140+
114141
}

0 commit comments

Comments
 (0)