BUGFIX: when querying the database pointer could be reused

This commit is contained in:
Jeroen De Meerleer 2022-09-26 15:55:53 +02:00
parent 3a95d23d8b
commit 3a48fd7e52
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 5 additions and 2 deletions

View File

@ -56,7 +56,7 @@ class DaemonCommand extends Command
$jobsToRun = $jobRepo->getJobsDue(); $jobsToRun = $jobRepo->getJobsDue();
if(!empty($jobsToRun)) { if(!empty($jobsToRun)) {
foreach($jobsToRun as $job) { foreach($jobsToRun as $key=>$job) {
if($job->getData('crontype') == 'reboot') { if($job->getData('crontype') == 'reboot') {
$str = @file_get_contents('/proc/uptime'); $str = @file_get_contents('/proc/uptime');
$num = floatval($str); $num = floatval($str);
@ -83,6 +83,8 @@ class DaemonCommand extends Command
$jobRepo->setJobRunning($job, false); $jobRepo->setJobRunning($job, false);
exit; exit;
} }
unset($jobsToRun[$key]);
unset($job);
} }
} }
$this->doctrine->getManager()->clear(); $this->doctrine->getManager()->clear();
@ -92,6 +94,7 @@ class DaemonCommand extends Command
$nextrun = max($jobRepo->getTimeOfNextRun(), time() + 1); $nextrun = max($jobRepo->getTimeOfNextRun(), time() + 1);
$sleepuntil = min($maxwait, $nextrun); $sleepuntil = min($maxwait, $nextrun);
if($sleepuntil > time()) time_sleep_until($sleepuntil); if($sleepuntil > time()) time_sleep_until($sleepuntil);
gc_collect_cycles();
} }
$output->writeln('Ended after ' . $timelimit . ' seconds'); $output->writeln('Ended after ' . $timelimit . ' seconds');
pcntl_wait($status); pcntl_wait($status);

View File

@ -14,7 +14,6 @@ use GuzzleHttp\Exception\GuzzleException;
use phpseclib3\Crypt\PublicKeyLoader; use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Net\SSH2; use phpseclib3\Net\SSH2;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/** /**
* *
@ -108,6 +107,7 @@ class JobRepository extends EntityRepository
*/ */
public function getJobsDue(): array public function getJobsDue(): array
{ {
$this->getEntityManager()->clear();
$qb = $this->createQueryBuilder('job'); $qb = $this->createQueryBuilder('job');
return $qb return $qb
->where( ->where(