aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/TaskProcessing
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2024-05-06 09:44:48 +0200
committerMarcel Klehr <mklehr@gmx.net>2024-05-14 11:38:40 +0200
commit996e5074ca43fbb049f496292a921012c3a49d63 (patch)
tree728042e99b795f01fbdf08a2fda477a28656f440 /lib/private/TaskProcessing
parent9effb55989af9cb0227f7fb1270e73b6160e44d6 (diff)
downloadnextcloud-server-996e5074ca43fbb049f496292a921012c3a49d63.tar.gz
nextcloud-server-996e5074ca43fbb049f496292a921012c3a49d63.zip
feat: Remove stale files in AppData as well
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/private/TaskProcessing')
-rw-r--r--lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php36
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php b/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php
index 54b63ac42fb..c68ead4e675 100644
--- a/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php
+++ b/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php
@@ -5,31 +5,63 @@ namespace OC\TaskProcessing;
use OC\TaskProcessing\Db\TaskMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
+use OCP\Files\AppData\IAppDataFactory;
+use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
+use OCP\Files\SimpleFS\ISimpleFolder;
use Psr\Log\LoggerInterface;
class RemoveOldTasksBackgroundJob extends TimedJob {
public const MAX_TASK_AGE_SECONDS = 60 * 50 * 24 * 7 * 4; // 4 weeks
+ private \OCP\Files\IAppData $appData;
public function __construct(
ITimeFactory $timeFactory,
private TaskMapper $taskMapper,
private LoggerInterface $logger,
+ IAppDataFactory $appDataFactory,
) {
parent::__construct($timeFactory);
$this->setInterval(60 * 60 * 24);
// can be deferred to maintenance window
$this->setTimeSensitivity(TimedJob::TIME_INSENSITIVE);
+ $this->appData = $appDataFactory->get('core');
}
/**
* @inheritDoc
*/
- protected function run($argument) {
+ protected function run($argument): void {
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]);
+ $this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]);
+ }
+ try {
+ $this->clearFilesOlderThan($this->appData->getFolder('text2image'), self::MAX_TASK_AGE_SECONDS);
+ $this->clearFilesOlderThan($this->appData->getFolder('audio2text'), self::MAX_TASK_AGE_SECONDS);
+ $this->clearFilesOlderThan($this->appData->getFolder('TaskProcessing'), self::MAX_TASK_AGE_SECONDS);
+ } catch (NotFoundException $e) {
+ // noop
+ }
+ }
+
+ /**
+ * @param ISimpleFolder $folder
+ * @param int $ageInSeconds
+ * @return void
+ */
+ private function clearFilesOlderThan(ISimpleFolder $folder, int $ageInSeconds): void {
+ foreach($folder->getDirectoryListing() as $file) {
+ if ($file->getMTime() < time() - $ageInSeconds) {
+ try {
+ $file->delete();
+ } catch (NotPermittedException $e) {
+ $this->logger->warning('Failed to delete a stale task processing file', ['exception' => $e]);
+ }
+ }
}
}
+
}