mirror of
https://github.com/nextcloud/server.git
synced 2026-05-26 03:04:35 -04:00
fix(TaskProcessingWorker): Only store config value every 60s
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
parent
3fa79ac7b3
commit
1bbd660648
2 changed files with 15 additions and 5 deletions
|
|
@ -10,6 +10,7 @@ namespace OC\Core\Command\TaskProcessing;
|
|||
|
||||
use OC\Core\Command\Base;
|
||||
use OC\Core\Command\InterruptedException;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\TaskProcessing\Exception\Exception;
|
||||
use OCP\TaskProcessing\Exception\NotFoundException;
|
||||
|
|
@ -25,6 +26,7 @@ class WorkerCommand extends Base {
|
|||
private readonly IManager $taskProcessingManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly IAppConfig $appConfig,
|
||||
private readonly ITimeFactory $timeFactory,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
|
@ -63,12 +65,13 @@ class WorkerCommand extends Base {
|
|||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$startTime = time();
|
||||
$startTime = $this->timeFactory->now()->getTimestamp();
|
||||
$timeout = (int)$input->getOption('timeout');
|
||||
$interval = (int)$input->getOption('interval');
|
||||
$once = $input->getOption('once') === true;
|
||||
/** @var list<string> $taskTypes */
|
||||
$taskTypes = $input->getOption('taskTypes');
|
||||
$lastConfigStorageTime = 0;
|
||||
|
||||
if ($timeout > 0) {
|
||||
$output->writeln('<info>Task processing worker will stop after ' . $timeout . ' seconds</info>');
|
||||
|
|
@ -76,7 +79,7 @@ class WorkerCommand extends Base {
|
|||
|
||||
while (true) {
|
||||
// Stop if timeout exceeded
|
||||
if ($timeout > 0 && ($startTime + $timeout) < time()) {
|
||||
if ($timeout > 0 && ($startTime + $timeout) < $this->timeFactory->now()->getTimestamp()) {
|
||||
$output->writeln('Timeout reached, exiting...', OutputInterface::VERBOSITY_VERBOSE);
|
||||
break;
|
||||
}
|
||||
|
|
@ -84,12 +87,15 @@ class WorkerCommand extends Base {
|
|||
// Handle SIGTERM/SIGINT gracefully
|
||||
try {
|
||||
$this->abortIfInterrupted();
|
||||
} catch (InterruptedException $e) {
|
||||
} catch (InterruptedException) {
|
||||
$output->writeln('<info>Task processing worker stopped</info>');
|
||||
break;
|
||||
}
|
||||
|
||||
$this->appConfig->setValueString('core', 'taskprocessing_worker_last_iteration', (string)time(), lazy: true);
|
||||
if ($lastConfigStorageTime < $this->timeFactory->now()->getTimestamp() - 60) {
|
||||
$this->appConfig->setValueString('core', 'taskprocessing_worker_last_iteration', (string)$this->timeFactory->now()->getTimestamp(), lazy: true);
|
||||
$lastConfigStorageTime = $this->timeFactory->now()->getTimestamp();
|
||||
}
|
||||
$processedTask = $this->processNextTask($output, $taskTypes);
|
||||
|
||||
if ($once) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
namespace Tests\Core\Command\TaskProcessing;
|
||||
|
||||
use OC\Core\Command\TaskProcessing\WorkerCommand;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\TaskProcessing\Exception\Exception;
|
||||
use OCP\TaskProcessing\Exception\NotFoundException;
|
||||
|
|
@ -26,6 +27,7 @@ class WorkerCommandTest extends TestCase {
|
|||
private IManager&MockObject $manager;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private IAppConfig&MockObject $appConfig;
|
||||
private ITimeFactory&MockObject $timeFactory;
|
||||
private WorkerCommand $command;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
@ -34,7 +36,9 @@ class WorkerCommandTest extends TestCase {
|
|||
$this->manager = $this->createMock(IManager::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->appConfig = $this->createMock(IAppConfig::class);
|
||||
$this->command = new WorkerCommand($this->manager, $this->logger, $this->appConfig);
|
||||
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
||||
$this->timeFactory->method('now')->willReturnCallback(fn() => new \DateTimeImmutable());
|
||||
$this->command = new WorkerCommand($this->manager, $this->logger, $this->appConfig, $this->timeFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue