-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Feat: Better reporting if something is wrong with taskprocessing #59958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3802c0d
feat(TaskProcessing): Add setup check for task processing worker status
marcelklehr 99fc7b2
fix(TaskProcessing): Make setup checks more sensitive
marcelklehr 2d18aed
fix: Register taskprocessing setup checks
marcelklehr 5548825
fix: Address review comment
marcelklehr 01ebeca
fix: Fix taskprocessing:worker command tests
marcelklehr beef1a6
fix(TaskProcessingWorkerIsRunning): Different message if the worker h…
marcelklehr f0a3b33
fix(TaskProcessingWorker): Only store config value every 60s
marcelklehr cbaf5fa
fix(TaskProcessingWorker): Adjust config key name
marcelklehr 3ed8bf2
fix: Run cs:fix
marcelklehr 1adf754
fix: Fix psalm issues
marcelklehr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
apps/settings/lib/SetupChecks/TaskProcessingWorkerIsRunning.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Settings\SetupChecks; | ||
|
|
||
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\IAppConfig; | ||
| use OCP\IL10N; | ||
| use OCP\SetupCheck\ISetupCheck; | ||
| use OCP\SetupCheck\SetupResult; | ||
| use OCP\TaskProcessing\IManager; | ||
|
|
||
| class TaskProcessingWorkerIsRunning implements ISetupCheck { | ||
|
|
||
| public const HAS_TASKS_IN_LAST_X_DAYS = 7; | ||
| public const IS_RUNNING_IN_LAST_X_MINUTES = 5; | ||
|
|
||
| public function __construct( | ||
| private readonly IL10N $l10n, | ||
| private readonly IManager $taskProcessingManager, | ||
| private readonly ITimeFactory $timeFactory, | ||
| private readonly IAppConfig $appConfig, | ||
| ) { | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getCategory(): string { | ||
| return 'ai'; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getName(): string { | ||
| return $this->l10n->t('Task Processing worker status'); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function run(): SetupResult { | ||
| $lastNDays = self::HAS_TASKS_IN_LAST_X_DAYS; | ||
| $tasks = $this->taskProcessingManager->getTasks(userId: '', scheduleAfter: $this->timeFactory->now()->getTimestamp() - (60 * 60 * 24 * $lastNDays)); | ||
| $taskCount = count($tasks); | ||
| if ($taskCount === 0) { | ||
| // In case taskprocessing is not used at all | ||
| return SetupResult::success( | ||
| $this->l10n->n( | ||
| 'No scheduled tasks in the last day.', | ||
| 'No scheduled tasks in the last %n days.', | ||
| $lastNDays | ||
| ) | ||
| ); | ||
| } | ||
| $lastIteration = (int)$this->appConfig->getValueString('core', 'ai.taskprocessing_worker_last_iteration', lazy: true); | ||
| if ($lastIteration > $this->timeFactory->now()->getTimestamp() - (60 * self::IS_RUNNING_IN_LAST_X_MINUTES)) { | ||
| return SetupResult::success( | ||
| $this->l10n->n('The Task Processing worker has run in the last minute.', 'The Task Processing worker has run in the last %n minutes.', self::IS_RUNNING_IN_LAST_X_MINUTES) | ||
| ); | ||
| } | ||
|
|
||
| if ($lastIteration > 0) { | ||
| return SetupResult::warning( | ||
| $this->l10n->t('The Task Processing worker does not seem to be running. The last run was at %s.', [date('Y-m-d H:i:s', $lastIteration)]) | ||
| ); | ||
| } | ||
|
|
||
| return SetupResult::warning( | ||
| $this->l10n->t('The Task Processing worker does not seem to be running. It seems it has never run so far.') | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
apps/settings/tests/SetupChecks/TaskProcessingWorkerIsRunningTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OCA\Settings\Tests; | ||
|
|
||
| use OCA\Settings\SetupChecks\TaskProcessingWorkerIsRunning; | ||
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\IAppConfig; | ||
| use OCP\IL10N; | ||
| use OCP\SetupCheck\SetupResult; | ||
| use OCP\TaskProcessing\IManager; | ||
| use OCP\TaskProcessing\Task; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Test\TestCase; | ||
|
|
||
| class TaskProcessingWorkerIsRunningTest extends TestCase { | ||
| private IL10N&MockObject $l10n; | ||
| private ITimeFactory&MockObject $timeFactory; | ||
| private IManager&MockObject $taskProcessingManager; | ||
| private IAppConfig&MockObject $appConfig; | ||
|
|
||
| private TaskProcessingWorkerIsRunning $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->appConfig = $this->getMockBuilder(IAppConfig::class)->getMock(); | ||
|
|
||
| $this->check = new TaskProcessingWorkerIsRunning( | ||
| $this->l10n, | ||
| $this->taskProcessingManager, | ||
| $this->timeFactory, | ||
| $this->appConfig | ||
| ); | ||
| } | ||
|
|
||
| public function testPass(): void { | ||
| $tasks = []; | ||
| for ($i = 0; $i < 10; $i++) { | ||
| $task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i); | ||
| $task->setStartedAt($this->timeFactory->now()->getTimestamp()); | ||
| $task->setScheduledAt($this->timeFactory->now()->getTimestamp()); | ||
| $task->setEndedAt($this->timeFactory->now()->getTimestamp()); | ||
| $task->setStatus(Task::STATUS_SUCCESSFUL); | ||
| $tasks[] = $task; | ||
| } | ||
| $this->taskProcessingManager->method('getTasks')->willReturn($tasks); | ||
| $this->timeFactory->method('now')->willReturn(new \DateTimeImmutable()); | ||
| $this->appConfig->method('getValueString')->willReturn((string)$this->timeFactory->now()->getTimestamp()); | ||
|
|
||
| $this->assertEquals(SetupResult::SUCCESS, $this->check->run()->getSeverity()); | ||
| } | ||
|
|
||
| public function testFail(): void { | ||
| $tasks = []; | ||
| for ($i = 0; $i < 10; $i++) { | ||
| $task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i); | ||
| $task->setStartedAt($this->timeFactory->now()->getTimestamp()); | ||
| $task->setScheduledAt($this->timeFactory->now()->getTimestamp()); | ||
| $task->setEndedAt($this->timeFactory->now()->getTimestamp()); | ||
| $task->setStatus(Task::STATUS_SUCCESSFUL); | ||
| $tasks[] = $task; | ||
| } | ||
| $this->taskProcessingManager->method('getTasks')->willReturn($tasks); | ||
| $this->timeFactory->method('now')->willReturn(new \DateTimeImmutable()); | ||
| $this->appConfig->method('getValueString')->willReturn((string)($this->timeFactory->now()->getTimestamp() - 60 * 10)); | ||
|
|
||
| $this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.