-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh: Add MaintenanceJob to trigger stuck clustering
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
- Loading branch information
1 parent
5488116
commit 16be71f
Showing
4 changed files
with
125 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/* | ||
* Copyright (c) 2024 The Recognize contributors. | ||
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file. | ||
*/ | ||
declare(strict_types=1); | ||
namespace OCA\Recognize\BackgroundJobs; | ||
|
||
use OCA\Recognize\Db\FaceDetectionMapper; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\BackgroundJob\IJobList; | ||
use OCP\BackgroundJob\TimedJob; | ||
use OCP\DB\Exception; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class MaintenanceJob extends TimedJob { | ||
|
||
public function __construct( | ||
ITimeFactory $time, | ||
private LoggerInterface $logger, | ||
private IJobList $jobList, | ||
private FaceDetectionMapper $faceDetectionMapper, | ||
) { | ||
parent::__construct($time); | ||
$this->setInterval(60 * 60 * 12); | ||
$this->setTimeSensitivity(self::TIME_INSENSITIVE); | ||
} | ||
|
||
/** | ||
* @param mixed $argument | ||
* @return void | ||
*/ | ||
protected function run($argument) { | ||
// Trigger clustering in case it's stuck | ||
try { | ||
$users = $this->faceDetectionMapper->getUsersForUnclustered(); | ||
} catch (Exception $e) { | ||
$this->logger->error($e->getMessage(), ['exception' => $e]); | ||
return; | ||
} | ||
foreach ($users as $userId) { | ||
$this->jobList->add(ClusterFacesJob::class, ['userId' => $userId]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters