From 969ee0d09925c7830ccc19db7e6328ae69e4c787 Mon Sep 17 00:00:00 2001 From: PT-ATA No One Date: Tue, 21 May 2024 11:41:00 +0200 Subject: [PATCH] Add logging for start and end of background jobs --- lib/BackgroundJobs/ScanJob.php | 6 ++++-- lib/BackgroundJobs/TagUnscannedJob.php | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/BackgroundJobs/ScanJob.php b/lib/BackgroundJobs/ScanJob.php index c1a31747..08df5d7a 100644 --- a/lib/BackgroundJobs/ScanJob.php +++ b/lib/BackgroundJobs/ScanJob.php @@ -28,7 +28,7 @@ public function __construct(LoggerInterface $logger, ITimeFactory $time, TagServ $this->scanService = $scanService; $this->appConfig = $appConfig; - $this->setInterval(5 * 60); + $this->setInterval(60); $this->setAllowParallelRuns(false); $this->setTimeSensitivity(self::TIME_SENSITIVE); } @@ -74,7 +74,7 @@ protected function run($argument): void } } - $this->logger->debug("Scanning " . count($fileIds) . " files: " . implode(", ", $fileIds)); + $this->logger->debug("Scanning files"); foreach ($fileIds as $fileId) { try { @@ -83,5 +83,7 @@ protected function run($argument): void $this->logger->error("Failed to scan file with id " . $fileId . ": " . $e->getMessage()); } } + + $this->logger->debug("Scanned " . count($fileIds) . " files"); } } diff --git a/lib/BackgroundJobs/TagUnscannedJob.php b/lib/BackgroundJobs/TagUnscannedJob.php index 42310139..7add2239 100644 --- a/lib/BackgroundJobs/TagUnscannedJob.php +++ b/lib/BackgroundJobs/TagUnscannedJob.php @@ -7,6 +7,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\DB\Exception; use OCP\IConfig; +use Psr\Log\LoggerInterface; class TagUnscannedJob extends TimedJob { @@ -14,13 +15,15 @@ class TagUnscannedJob extends TimedJob private TagService $tagService; private IConfig $appConfig; + private LoggerInterface $logger; - public function __construct(ITimeFactory $time, IConfig $appConfig, TagService $tagService) + public function __construct(ITimeFactory $time, IConfig $appConfig, TagService $tagService, LoggerInterface $logger) { parent::__construct($time); $this->appConfig = $appConfig; $this->tagService = $tagService; + $this->logger = $logger; $this->setInterval(60); $this->setAllowParallelRuns(false); @@ -40,6 +43,8 @@ protected function run($argument): void return; } + $this->logger->debug("Tagging unscanned files"); + $unscannedTag = $this->tagService->getTag(TagService::UNSCANNED); $maliciousTag = $this->tagService->getTag(TagService::MALICIOUS); $pupTag = $this->tagService->getTag(TagService::PUP); @@ -49,15 +54,13 @@ protected function run($argument): void $fileIds = $this->tagService->getFileIdsWithoutTags($excludedTagIds, 10000); - if (count($fileIds) == 0) { - return; - } - foreach ($fileIds as $fileId) { if ($this->tagService->hasCleanMaliciousOrPupTag($fileId)) { continue; } $this->tagService->setTag($fileId, TagService::UNSCANNED); } + + $this->logger->debug("Tagged " . count($fileIds) . " unscanned files"); } }