-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathTaskProcessingWorkerIsRunning.php
More file actions
74 lines (62 loc) · 2.22 KB
/
TaskProcessingWorkerIsRunning.php
File metadata and controls
74 lines (62 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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.')
);
}
}