2023-06-28 08:59:20 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-06-28 08:59:20 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2023-07-14 09:59:50 -04:00
|
|
|
namespace OC\TextProcessing;
|
2023-06-28 08:59:20 -04:00
|
|
|
|
2023-07-14 09:59:50 -04:00
|
|
|
use OC\TextProcessing\Db\TaskMapper;
|
2023-06-28 08:59:20 -04:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
|
use OCP\BackgroundJob\TimedJob;
|
|
|
|
|
use OCP\DB\Exception;
|
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
|
|
class RemoveOldTasksBackgroundJob extends TimedJob {
|
2024-10-07 11:36:55 -04:00
|
|
|
public const MAX_TASK_AGE_SECONDS = 60 * 60 * 24 * 7; // 1 week
|
2023-06-28 08:59:20 -04:00
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
ITimeFactory $timeFactory,
|
|
|
|
|
private TaskMapper $taskMapper,
|
|
|
|
|
private LoggerInterface $logger,
|
|
|
|
|
) {
|
|
|
|
|
parent::__construct($timeFactory);
|
|
|
|
|
$this->setInterval(60 * 60 * 24);
|
2024-10-07 11:36:55 -04:00
|
|
|
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
|
2023-06-28 08:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed $argument
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
*/
|
|
|
|
|
protected function run($argument) {
|
|
|
|
|
try {
|
|
|
|
|
$this->taskMapper->deleteOlderThan(self::MAX_TASK_AGE_SECONDS);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$this->logger->warning('Failed to delete stale language model tasks', ['exception' => $e]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|