Skip to content

Commit

Permalink
fix(ClassifierJob): Fix concurrency limit being overzealous
Browse files Browse the repository at this point in the history
see #967

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Oct 15, 2023
1 parent 0fe28db commit 575d3fa
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/BackgroundJobs/ClassifierJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
use Psr\Log\LoggerInterface;

abstract class ClassifierJob extends TimedJob {

public function __construct(
ITimeFactory $time,
private LoggerInterface $logger,
private QueueService $queue,
private IUserMountCache $userMountCache,
private IJobList $jobList,
private SettingsService $settingsService
private SettingsService $settingsService,
) {
parent::__construct($time);
$this->setInterval(60 * 5);
Expand All @@ -34,7 +34,7 @@ public function __construct(

protected function runClassifier(string $model, array $argument): void {
sleep(10);
if ($this->settingsService->getSetting('concurrency.enabled') !== 'true' && $this->anyClassifierJobsRunning()) {
if ($this->settingsService->getSetting('concurrency.enabled') !== 'true' && $this->anyOtherClassifierJobsRunning()) {
$this->logger->debug('Stalling job '.static::class.' with argument ' . var_export($argument, true) . ' because other classifiers are already reserved');
return;
}
Expand Down Expand Up @@ -114,16 +114,20 @@ abstract protected function classify(array $files) : void;
/**
* @return bool
*/
private function anyClassifierJobsRunning() {
private function anyOtherClassifierJobsRunning() {
foreach ([
ClassifyFacesJob::class,
ClassifyImagenetJob::class,
ClassifyLandmarksJob::class,
ClassifyMovinetJob::class,
ClassifyMusicnnJob::class,
] as $jobClass) {
if ($this->jobList->hasReservedJob($jobClass)) {
return true;
if ($jobClass === self::class) {
continue;
} else {
if ($this->jobList->hasReservedJob($jobClass)) {
return true;
}
}
}
return false;
Expand Down

0 comments on commit 575d3fa

Please sign in to comment.