Skip to content

Commit 4ec76cf

Browse files
authored
Merge pull request #55715 from nextcloud/fix/taskprocessing/setupcheck-pickupspeed
fix(settings): Improve TaskProcessingPickupSpeed setup check
2 parents 5aa1f5b + 5c5c938 commit 4ec76cf

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

apps/settings/lib/SetupChecks/TaskProcessingPickupSpeed.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
class TaskProcessingPickupSpeed implements ISetupCheck {
1919
public const MAX_SLOW_PERCENTAGE = 0.2;
20-
public const TIME_SPAN = 24;
20+
21+
public const MAX_DAYS = 14;
2122

2223
public function __construct(
2324
private IL10N $l10n,
@@ -35,10 +36,22 @@ public function getName(): string {
3536
}
3637

3738
public function run(): SetupResult {
38-
$tasks = $this->taskProcessingManager->getTasks(userId: '', scheduleAfter: $this->timeFactory->now()->getTimestamp() - 60 * 60 * self::TIME_SPAN); // userId: '' means no filter, whereas null would mean guest
39-
$taskCount = count($tasks);
39+
$taskCount = 0;
40+
$lastNDays = 1;
41+
while ($taskCount === 0 && $lastNDays < self::MAX_DAYS) {
42+
$lastNDays++;
43+
// userId: '' means no filter, whereas null would mean guest
44+
$tasks = $this->taskProcessingManager->getTasks(userId: '', scheduleAfter: $this->timeFactory->now()->getTimestamp() - (60 * 60 * 24 * $lastNDays));
45+
$taskCount = count($tasks);
46+
}
4047
if ($taskCount === 0) {
41-
return SetupResult::success($this->l10n->n('No scheduled tasks in the last %n hour.', 'No scheduled tasks in the last %n hours.', self::TIME_SPAN));
48+
return SetupResult::success(
49+
$this->l10n->n(
50+
'No scheduled tasks in the last day.',
51+
'No scheduled tasks in the last %n days.',
52+
$lastNDays
53+
)
54+
);
4255
}
4356
$slowCount = 0;
4457
foreach ($tasks as $task) {
@@ -54,10 +67,23 @@ public function run(): SetupResult {
5467
}
5568
}
5669

57-
if ($slowCount / $taskCount < self::MAX_SLOW_PERCENTAGE) {
58-
return SetupResult::success($this->l10n->n('The task pickup speed has been ok in the last %n hour.', 'The task pickup speed has been ok in the last %n hours.', self::TIME_SPAN));
70+
if (($slowCount / $taskCount) < self::MAX_SLOW_PERCENTAGE) {
71+
return SetupResult::success(
72+
$this->l10n->n(
73+
'The task pickup speed has been ok in the last day.',
74+
'The task pickup speed has been ok in the last %n days.',
75+
$lastNDays
76+
)
77+
);
5978
} else {
60-
return SetupResult::warning($this->l10n->n('The task pickup speed has been slow in the last %n hour. Many tasks took longer than 4 minutes to be picked up. Consider setting up a worker to process tasks in the background.', 'The task pickup speed has been slow in the last %n hours. Many tasks took longer than 4 minutes to be picked up. Consider setting up a worker to process tasks in the background.', self::TIME_SPAN), 'https://docs.nextcloud.com/server/latest/admin_manual/ai/overview.html#improve-ai-task-pickup-speed');
79+
return SetupResult::warning(
80+
$this->l10n->n(
81+
'The task pickup speed has been slow in the last day. Many tasks took longer than 4 minutes to be picked up. Consider setting up a worker to process tasks in the background.',
82+
'The task pickup speed has been slow in the last %n days. Many tasks took longer than 4 minutes to be picked up. Consider setting up a worker to process tasks in the background.',
83+
$lastNDays
84+
),
85+
'https://docs.nextcloud.com/server/latest/admin_manual/ai/overview.html#improve-ai-task-pickup-speed'
86+
);
6187
}
6288
}
6389
}

0 commit comments

Comments
 (0)