-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathTrainIpV6OnceJob.php
More file actions
51 lines (44 loc) · 1.29 KB
/
TrainIpV6OnceJob.php
File metadata and controls
51 lines (44 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\SuspiciousLogin\BackgroundJob;
use OCA\SuspiciousLogin\Exception\InsufficientDataException;
use OCA\SuspiciousLogin\Service\IpV6Strategy;
use OCA\SuspiciousLogin\Service\TrainingDataConfig;
use OCA\SuspiciousLogin\Service\TrainService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use Psr\Log\LoggerInterface;
use Throwable;
class TrainIpV6OnceJob extends QueuedJob {
public function __construct(
private TrainService $trainService,
private LoggerInterface $logger,
ITimeFactory $time,
) {
parent::__construct($time);
}
/**
* @param $argument
*
* @return void
*/
#[\Override]
protected function run($argument) {
try {
$strategy = new IpV6Strategy();
$this->trainService->train(
$strategy->getDefaultMlpConfig(),
TrainingDataConfig::default(),
$strategy
);
} catch (InsufficientDataException $ex) {
$this->logger->info('No suspicious login model for IPv6 trained because of insufficient data', ['exception' => $ex]);
} catch (Throwable $ex) {
$this->logger->error('Caught unknown error during IPv6 background training', ['exception' => $ex]);
}
}
}