From 4b2acee64be7331061f88c9b2443fa74edd488d4 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 30 Apr 2024 16:30:24 +0200 Subject: test: Add OldTasksShouldBeCleanedUp test Signed-off-by: Marcel Klehr --- lib/private/TaskProcessing/Db/TaskMapper.php | 2 +- lib/private/TaskProcessing/Manager.php | 2 +- .../TaskProcessing/RemoveOldTasksBackgroundJob.php | 46 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php (limited to 'lib/private') diff --git a/lib/private/TaskProcessing/Db/TaskMapper.php b/lib/private/TaskProcessing/Db/TaskMapper.php index a1cc3d1409a..f8a1adc695c 100644 --- a/lib/private/TaskProcessing/Db/TaskMapper.php +++ b/lib/private/TaskProcessing/Db/TaskMapper.php @@ -127,7 +127,7 @@ class TaskMapper extends QBMapper { public function deleteOlderThan(int $timeout): int { $qb = $this->db->getQueryBuilder(); $qb->delete($this->tableName) - ->where($qb->expr()->lt('last_updated', $qb->createPositionalParameter(time() - $timeout))); + ->where($qb->expr()->lt('last_updated', $qb->createPositionalParameter($this->timeFactory->getDateTime()->getTimestamp() - $timeout))); return $qb->executeStatement(); } diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index 9ea92691f2a..4cc2119f299 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -711,7 +711,7 @@ class Manager implements IManager { $this->validateOutput($optionalOutputShape, $result, true); $output = $this->removeSuperfluousArrayKeys($result, $outputShape, $optionalOutputShape); // extract base64 data and put it in files, replace it with file ids - $output = $this->encapsulateInputOutputFileData($output, $outputShape, $optionalOutputShape); + $output = $this->encapsulateOutputFileData($output, $outputShape, $optionalOutputShape); $task->setOutput($output); $task->setProgress(1); $task->setStatus(Task::STATUS_SUCCESSFUL); diff --git a/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php b/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php new file mode 100644 index 00000000000..76786412059 --- /dev/null +++ b/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php @@ -0,0 +1,46 @@ +setInterval(60 * 60 * 24); + // can be deferred to maintenance window + $this->setTimeSensitivity(TimedJob::TIME_INSENSITIVE); + } + + + /** + * @inheritDoc + */ + protected function run($argument) { + try { + $this->taskMapper->deleteOlderThan(self::MAX_TASK_AGE_SECONDS); + } catch (\OCP\DB\Exception $e) { + $this->logger->warning('Failed to delete stale language model tasks', ['exception' => $e]); + } + } +} -- cgit v1.2.3