Skip to content

Commit

Permalink
Add logging for start and end of background jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ata-no-one committed May 21, 2024
1 parent ab09b58 commit 969ee0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/BackgroundJobs/ScanJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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");
}
}
13 changes: 8 additions & 5 deletions lib/BackgroundJobs/TagUnscannedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\IConfig;
use Psr\Log\LoggerInterface;

class TagUnscannedJob extends TimedJob
{
private const APP_ID = "gdatavaas";

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);
Expand All @@ -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);
Expand All @@ -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");
}
}

0 comments on commit 969ee0d

Please sign in to comment.