@@ -16,48 +16,48 @@ |
||
16 | 16 | use OCP\TaskProcessing\IManager; |
17 | 17 | |
18 | 18 | class TaskProcessingPickupSpeed implements ISetupCheck { |
19 | - public const MAX_SLOW_PERCENTAGE = 0.2; |
|
20 | - public const TIME_SPAN = 24; |
|
21 | - |
|
22 | - public function __construct( |
|
23 | - private IL10N $l10n, |
|
24 | - private IManager $taskProcessingManager, |
|
25 | - private ITimeFactory $timeFactory, |
|
26 | - ) { |
|
27 | - } |
|
28 | - |
|
29 | - public function getCategory(): string { |
|
30 | - return 'ai'; |
|
31 | - } |
|
32 | - |
|
33 | - public function getName(): string { |
|
34 | - return $this->l10n->t('Task Processing pickup speed'); |
|
35 | - } |
|
36 | - |
|
37 | - 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); |
|
40 | - 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)); |
|
42 | - } |
|
43 | - $slowCount = 0; |
|
44 | - foreach ($tasks as $task) { |
|
45 | - if ($task->getStartedAt() === null) { |
|
46 | - continue; // task was not picked up yet |
|
47 | - } |
|
48 | - if ($task->getScheduledAt() === null) { |
|
49 | - continue; // task was not scheduled yet -- should not happen, but the API specifies null as return value |
|
50 | - } |
|
51 | - $pickupDelay = $task->getScheduledAt() - $task->getStartedAt(); |
|
52 | - if ($pickupDelay > 60 * 4) { |
|
53 | - $slowCount++; // task pickup took longer than 4 minutes |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
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)); |
|
59 | - } 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'); |
|
61 | - } |
|
62 | - } |
|
19 | + public const MAX_SLOW_PERCENTAGE = 0.2; |
|
20 | + public const TIME_SPAN = 24; |
|
21 | + |
|
22 | + public function __construct( |
|
23 | + private IL10N $l10n, |
|
24 | + private IManager $taskProcessingManager, |
|
25 | + private ITimeFactory $timeFactory, |
|
26 | + ) { |
|
27 | + } |
|
28 | + |
|
29 | + public function getCategory(): string { |
|
30 | + return 'ai'; |
|
31 | + } |
|
32 | + |
|
33 | + public function getName(): string { |
|
34 | + return $this->l10n->t('Task Processing pickup speed'); |
|
35 | + } |
|
36 | + |
|
37 | + 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); |
|
40 | + 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)); |
|
42 | + } |
|
43 | + $slowCount = 0; |
|
44 | + foreach ($tasks as $task) { |
|
45 | + if ($task->getStartedAt() === null) { |
|
46 | + continue; // task was not picked up yet |
|
47 | + } |
|
48 | + if ($task->getScheduledAt() === null) { |
|
49 | + continue; // task was not scheduled yet -- should not happen, but the API specifies null as return value |
|
50 | + } |
|
51 | + $pickupDelay = $task->getScheduledAt() - $task->getStartedAt(); |
|
52 | + if ($pickupDelay > 60 * 4) { |
|
53 | + $slowCount++; // task pickup took longer than 4 minutes |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
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)); |
|
59 | + } 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'); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | } |