@@ -16,64 +16,64 @@ |
||
| 16 | 16 | use Psr\Log\LoggerInterface; |
| 17 | 17 | |
| 18 | 18 | class RemoveOldTasksBackgroundJob extends TimedJob { |
| 19 | - public const MAX_TASK_AGE_SECONDS = 60 * 60 * 24 * 30 * 4; // 4 months |
|
| 20 | - private \OCP\Files\IAppData $appData; |
|
| 19 | + public const MAX_TASK_AGE_SECONDS = 60 * 60 * 24 * 30 * 4; // 4 months |
|
| 20 | + private \OCP\Files\IAppData $appData; |
|
| 21 | 21 | |
| 22 | - public function __construct( |
|
| 23 | - ITimeFactory $timeFactory, |
|
| 24 | - private TaskMapper $taskMapper, |
|
| 25 | - private LoggerInterface $logger, |
|
| 26 | - IAppDataFactory $appDataFactory, |
|
| 27 | - ) { |
|
| 28 | - parent::__construct($timeFactory); |
|
| 29 | - $this->setInterval(60 * 60 * 24); |
|
| 30 | - // can be deferred to maintenance window |
|
| 31 | - $this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|
| 32 | - $this->appData = $appDataFactory->get('core'); |
|
| 33 | - } |
|
| 22 | + public function __construct( |
|
| 23 | + ITimeFactory $timeFactory, |
|
| 24 | + private TaskMapper $taskMapper, |
|
| 25 | + private LoggerInterface $logger, |
|
| 26 | + IAppDataFactory $appDataFactory, |
|
| 27 | + ) { |
|
| 28 | + parent::__construct($timeFactory); |
|
| 29 | + $this->setInterval(60 * 60 * 24); |
|
| 30 | + // can be deferred to maintenance window |
|
| 31 | + $this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|
| 32 | + $this->appData = $appDataFactory->get('core'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @inheritDoc |
|
| 38 | - */ |
|
| 39 | - protected function run($argument): void { |
|
| 40 | - try { |
|
| 41 | - $this->taskMapper->deleteOlderThan(self::MAX_TASK_AGE_SECONDS); |
|
| 42 | - } catch (\OCP\DB\Exception $e) { |
|
| 43 | - $this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]); |
|
| 44 | - } |
|
| 45 | - try { |
|
| 46 | - $this->clearFilesOlderThan($this->appData->getFolder('text2image'), self::MAX_TASK_AGE_SECONDS); |
|
| 47 | - } catch (NotFoundException $e) { |
|
| 48 | - // noop |
|
| 49 | - } |
|
| 50 | - try { |
|
| 51 | - $this->clearFilesOlderThan($this->appData->getFolder('audio2text'), self::MAX_TASK_AGE_SECONDS); |
|
| 52 | - } catch (NotFoundException $e) { |
|
| 53 | - // noop |
|
| 54 | - } |
|
| 55 | - try { |
|
| 56 | - $this->clearFilesOlderThan($this->appData->getFolder('TaskProcessing'), self::MAX_TASK_AGE_SECONDS); |
|
| 57 | - } catch (NotFoundException $e) { |
|
| 58 | - // noop |
|
| 59 | - } |
|
| 60 | - } |
|
| 36 | + /** |
|
| 37 | + * @inheritDoc |
|
| 38 | + */ |
|
| 39 | + protected function run($argument): void { |
|
| 40 | + try { |
|
| 41 | + $this->taskMapper->deleteOlderThan(self::MAX_TASK_AGE_SECONDS); |
|
| 42 | + } catch (\OCP\DB\Exception $e) { |
|
| 43 | + $this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]); |
|
| 44 | + } |
|
| 45 | + try { |
|
| 46 | + $this->clearFilesOlderThan($this->appData->getFolder('text2image'), self::MAX_TASK_AGE_SECONDS); |
|
| 47 | + } catch (NotFoundException $e) { |
|
| 48 | + // noop |
|
| 49 | + } |
|
| 50 | + try { |
|
| 51 | + $this->clearFilesOlderThan($this->appData->getFolder('audio2text'), self::MAX_TASK_AGE_SECONDS); |
|
| 52 | + } catch (NotFoundException $e) { |
|
| 53 | + // noop |
|
| 54 | + } |
|
| 55 | + try { |
|
| 56 | + $this->clearFilesOlderThan($this->appData->getFolder('TaskProcessing'), self::MAX_TASK_AGE_SECONDS); |
|
| 57 | + } catch (NotFoundException $e) { |
|
| 58 | + // noop |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param ISimpleFolder $folder |
|
| 64 | - * @param int $ageInSeconds |
|
| 65 | - * @return void |
|
| 66 | - */ |
|
| 67 | - private function clearFilesOlderThan(ISimpleFolder $folder, int $ageInSeconds): void { |
|
| 68 | - foreach ($folder->getDirectoryListing() as $file) { |
|
| 69 | - if ($file->getMTime() < time() - $ageInSeconds) { |
|
| 70 | - try { |
|
| 71 | - $file->delete(); |
|
| 72 | - } catch (NotPermittedException $e) { |
|
| 73 | - $this->logger->warning('Failed to delete a stale task processing file', ['exception' => $e]); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 62 | + /** |
|
| 63 | + * @param ISimpleFolder $folder |
|
| 64 | + * @param int $ageInSeconds |
|
| 65 | + * @return void |
|
| 66 | + */ |
|
| 67 | + private function clearFilesOlderThan(ISimpleFolder $folder, int $ageInSeconds): void { |
|
| 68 | + foreach ($folder->getDirectoryListing() as $file) { |
|
| 69 | + if ($file->getMTime() < time() - $ageInSeconds) { |
|
| 70 | + try { |
|
| 71 | + $file->delete(); |
|
| 72 | + } catch (NotPermittedException $e) { |
|
| 73 | + $this->logger->warning('Failed to delete a stale task processing file', ['exception' => $e]); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | } |