@@ -16,74 +16,74 @@ |
||
| 16 | 16 | use OCP\TaskProcessing\IManager; |
| 17 | 17 | |
| 18 | 18 | class TaskProcessingPickupSpeed implements ISetupCheck { |
| 19 | - public const MAX_SLOW_PERCENTAGE = 0.2; |
|
| 19 | + public const MAX_SLOW_PERCENTAGE = 0.2; |
|
| 20 | 20 | |
| 21 | - public const MAX_DAYS = 14; |
|
| 21 | + public const MAX_DAYS = 14; |
|
| 22 | 22 | |
| 23 | - public function __construct( |
|
| 24 | - private IL10N $l10n, |
|
| 25 | - private IManager $taskProcessingManager, |
|
| 26 | - private ITimeFactory $timeFactory, |
|
| 27 | - ) { |
|
| 28 | - } |
|
| 23 | + public function __construct( |
|
| 24 | + private IL10N $l10n, |
|
| 25 | + private IManager $taskProcessingManager, |
|
| 26 | + private ITimeFactory $timeFactory, |
|
| 27 | + ) { |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function getCategory(): string { |
|
| 31 | - return 'ai'; |
|
| 32 | - } |
|
| 30 | + public function getCategory(): string { |
|
| 31 | + return 'ai'; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function getName(): string { |
|
| 35 | - return $this->l10n->t('Task Processing pickup speed'); |
|
| 36 | - } |
|
| 34 | + public function getName(): string { |
|
| 35 | + return $this->l10n->t('Task Processing pickup speed'); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function run(): SetupResult { |
|
| 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 | - } |
|
| 47 | - if ($taskCount === 0) { |
|
| 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 | - ); |
|
| 55 | - } |
|
| 56 | - $slowCount = 0; |
|
| 57 | - foreach ($tasks as $task) { |
|
| 58 | - if ($task->getStartedAt() === null) { |
|
| 59 | - continue; // task was not picked up yet |
|
| 60 | - } |
|
| 61 | - if ($task->getScheduledAt() === null) { |
|
| 62 | - continue; // task was not scheduled yet -- should not happen, but the API specifies null as return value |
|
| 63 | - } |
|
| 64 | - $pickupDelay = $task->getScheduledAt() - $task->getStartedAt(); |
|
| 65 | - if ($pickupDelay > 60 * 4) { |
|
| 66 | - $slowCount++; // task pickup took longer than 4 minutes |
|
| 67 | - } |
|
| 68 | - } |
|
| 38 | + public function run(): SetupResult { |
|
| 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 | + } |
|
| 47 | + if ($taskCount === 0) { |
|
| 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 | + ); |
|
| 55 | + } |
|
| 56 | + $slowCount = 0; |
|
| 57 | + foreach ($tasks as $task) { |
|
| 58 | + if ($task->getStartedAt() === null) { |
|
| 59 | + continue; // task was not picked up yet |
|
| 60 | + } |
|
| 61 | + if ($task->getScheduledAt() === null) { |
|
| 62 | + continue; // task was not scheduled yet -- should not happen, but the API specifies null as return value |
|
| 63 | + } |
|
| 64 | + $pickupDelay = $task->getScheduledAt() - $task->getStartedAt(); |
|
| 65 | + if ($pickupDelay > 60 * 4) { |
|
| 66 | + $slowCount++; // task pickup took longer than 4 minutes |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 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 | - ); |
|
| 78 | - } else { |
|
| 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 | - ); |
|
| 87 | - } |
|
| 88 | - } |
|
| 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 | + ); |
|
| 78 | + } else { |
|
| 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 | + ); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | } |