Compare commits

...

2 Commits

Author SHA1 Message Date
Marcel Klehr c28a4cdb95 fix(settings): Introduce TaskProcessingSuccessRate setup check
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
2025-10-13 14:32:30 +02:00
Marcel Klehr 22388c975a fix(settings): Introduce TaskProcessingSuccessRate setup check
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
2025-10-13 14:28:10 +02:00
5 changed files with 165 additions and 0 deletions
@@ -135,6 +135,7 @@ return array(
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => $baseDir . '/../lib/SetupChecks/SupportedDatabase.php',
'OCA\\Settings\\SetupChecks\\SystemIs64bit' => $baseDir . '/../lib/SetupChecks/SystemIs64bit.php',
'OCA\\Settings\\SetupChecks\\TaskProcessingPickupSpeed' => $baseDir . '/../lib/SetupChecks/TaskProcessingPickupSpeed.php',
'OCA\\Settings\\SetupChecks\\TaskProcessingSuccessRate' => $baseDir . '/../lib/SetupChecks/TaskProcessingSuccessRate.php',
'OCA\\Settings\\SetupChecks\\TempSpaceAvailable' => $baseDir . '/../lib/SetupChecks/TempSpaceAvailable.php',
'OCA\\Settings\\SetupChecks\\TransactionIsolation' => $baseDir . '/../lib/SetupChecks/TransactionIsolation.php',
'OCA\\Settings\\SetupChecks\\WellKnownUrls' => $baseDir . '/../lib/SetupChecks/WellKnownUrls.php',
@@ -150,6 +150,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SupportedDatabase.php',
'OCA\\Settings\\SetupChecks\\SystemIs64bit' => __DIR__ . '/..' . '/../lib/SetupChecks/SystemIs64bit.php',
'OCA\\Settings\\SetupChecks\\TaskProcessingPickupSpeed' => __DIR__ . '/..' . '/../lib/SetupChecks/TaskProcessingPickupSpeed.php',
'OCA\\Settings\\SetupChecks\\TaskProcessingSuccessRate' => __DIR__ . '/..' . '/../lib/SetupChecks/TaskProcessingSuccessRate.php',
'OCA\\Settings\\SetupChecks\\TempSpaceAvailable' => __DIR__ . '/..' . '/../lib/SetupChecks/TempSpaceAvailable.php',
'OCA\\Settings\\SetupChecks\\TransactionIsolation' => __DIR__ . '/..' . '/../lib/SetupChecks/TransactionIsolation.php',
'OCA\\Settings\\SetupChecks\\WellKnownUrls' => __DIR__ . '/..' . '/../lib/SetupChecks/WellKnownUrls.php',
@@ -76,6 +76,7 @@ use OCA\Settings\SetupChecks\TempSpaceAvailable;
use OCA\Settings\SetupChecks\TransactionIsolation;
use OCA\Settings\SetupChecks\WellKnownUrls;
use OCA\Settings\SetupChecks\Woff2Loading;
use OCA\Settings\Tests\TaskProcessingSuccessRateTest;
use OCA\Settings\UserMigration\AccountMigrator;
use OCA\Settings\WellKnown\ChangePasswordHandler;
use OCA\Settings\WellKnown\SecurityTxtHandler;
@@ -211,6 +212,7 @@ class Application extends App implements IBootstrap {
$context->registerSetupCheck(SupportedDatabase::class);
$context->registerSetupCheck(SystemIs64bit::class);
$context->registerSetupCheck(TaskProcessingPickupSpeed::class);
$context->registerSetupCheck(TaskProcessingSuccessRateTest::class);
$context->registerSetupCheck(TempSpaceAvailable::class);
$context->registerSetupCheck(TransactionIsolation::class);
$context->registerSetupCheck(PushService::class);
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\SetupChecks;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IL10N;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;
use OCP\TaskProcessing\IManager;
use OCP\TaskProcessing\Task;
class TaskProcessingSuccessRate implements ISetupCheck {
public const MAX_FAILURE_PERCENTAGE = 0.2;
public const MAX_DAYS = 14;
public function __construct(
private IL10N $l10n,
private IManager $taskProcessingManager,
private ITimeFactory $timeFactory,
) {
}
public function getCategory(): string {
return 'ai';
}
public function getName(): string {
return $this->l10n->t('Task Processing pickup speed');
}
public function run(): SetupResult {
$taskCount = 0;
$lastNDays = 1;
while ($taskCount === 0 && $lastNDays < self::MAX_DAYS) {
$lastNDays++;
$tasks = $this->taskProcessingManager->getTasks(userId: '', scheduleAfter: $this->timeFactory->now()->getTimestamp() - 60 * 60 * 24 * $lastNDays); // userId: '' means no filter, whereas null would mean guest
$taskCount = count($tasks);
}
if ($taskCount === 0) {
return SetupResult::success(
$this->l10n->n(
'No scheduled tasks in the last %n hour.',
'No scheduled tasks in the last %n hours.',
24 * $lastNDays
)
);
}
$failedCount = 0;
foreach ($tasks as $task) {
if ($task->getEndedAt() !== null) {
continue; // task was not picked up yet
}
$status = $task->getStatus();
if ($status === Task::STATUS_FAILED) {
$failedCount++; // task pickup took longer than 4 minutes
}
}
if ($failedCount / $taskCount < self::MAX_FAILURE_PERCENTAGE) {
return SetupResult::success(
$this->l10n->n(
'Most tasks were successful in the last %n hour.',
'Most tasks were successful in the last %n hours.',
24 * $lastNDays
)
);
} else {
return SetupResult::warning(
$this->l10n->n(
'A lot of tasks failed in the last %n hour. Consider checking the nextcloud log for errors and investigating whether the AI provider apps have been set up correctly.',
'A lot of tasks failed in the last %n hours. Consider checking the nextcloud log for errors and investigating whether the AI provider apps have been set up correctly.',
24 * $lastNDays
),
'https://docs.nextcloud.com/server/latest/admin_manual/ai/insight_and_debugging.html'
);
}
}
}
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests;
use OCA\Settings\SetupChecks\TaskProcessingPickupSpeed;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IL10N;
use OCP\SetupCheck\SetupResult;
use OCP\TaskProcessing\IManager;
use OCP\TaskProcessing\Task;
use Test\TestCase;
class TaskProcessingSuccessRateTest extends TestCase {
private IL10N $l10n;
private ITimeFactory $timeFactory;
private IManager $taskProcessingManager;
private TaskProcessingPickupSpeed $check;
protected function setUp(): void {
parent::setUp();
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
$this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
$this->taskProcessingManager = $this->getMockBuilder(IManager::class)->getMock();
$this->check = new TaskProcessingPickupSpeed(
$this->l10n,
$this->taskProcessingManager,
$this->timeFactory,
);
}
public function testPass(): void {
$tasks = [];
for ($i = 0; $i < 100; $i++) {
$task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
$task->setStartedAt(0);
$task->setEndedAt(1);
if ($i < 15) {
$task->setStatus(Task::STATUS_FAILED); // 15% get FAILED
} else {
$task->setStatus(Task::STATUS_SUCCESSFUL); // the rest gets SUCCESS
}
$tasks[] = $task;
}
$this->taskProcessingManager->method('getTasks')->willReturn($tasks);
$this->assertEquals(SetupResult::SUCCESS, $this->check->run()->getSeverity());
}
public function testFail(): void {
$tasks = [];
for ($i = 0; $i < 100; $i++) {
$task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
$task->setStartedAt(0);
$task->setEndedAt(1);
if ($i < 30) {
$task->setStatus(Task::STATUS_FAILED); // 30% get FAILED
} else {
$task->setStatus(Task::STATUS_SUCCESSFUL); // the rest gets SUCCESS
}
$tasks[] = $task;
}
$this->taskProcessingManager->method('getTasks')->willReturn($tasks);
$this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
}
}