Reimplemented periodic check

This commit is contained in:
Jeroen De Meerleer 2022-08-23 16:40:12 +02:00
parent cec29bb426
commit 3d5863e77a
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 36 additions and 1 deletions

View File

@ -86,7 +86,11 @@ class DaemonCommand extends Command
}
}
$this->doctrine->getManager()->clear();
sleep(1);
$maxwait = time() + 30;
$nextrun = $jobRepo->getTimeOfNextRun();
$sleepuntil = min($maxwait, $nextrun);
if($sleepuntil > time()) time_sleep_until($sleepuntil);
}
$output->writeln('Ended after ' . $timelimit . ' seconds');
pcntl_wait($status);

View File

@ -589,6 +589,37 @@ class JobRepository extends EntityRepository
return ['success' => true, 'message' => 'Cronjob succesfully edited'];
}
public function getTimeOfNextRun()
{
if(!empty($this->getJobsDue())) return time();
$qb = $this->createQueryBuilder('job');
$firstScheduledJob = $qb
->where('job.running = 0')
->orderBy('job.nextrun')
->getQuery()->getResult();
$firstRebootJob = $qb
->where('job.running > 2')
->orderBy('job.running')
->getQuery()->getResult();
if(empty($firstScheduledJob)) {
$val1 = PHP_INT_MAX;
} else {
$val1 = $firstScheduledJob[0]->getNextRun();
}
if(empty($firstRebootJob)) {
$val2 = PHP_INT_MAX;
} else {
$val2 = $firstRebootJob[0]->getRunning();
}
return min($val1, $val2);
}
/**
* @param array $values
* @param Job|null $job