diff --git a/src/Command/DaemonCommand.php b/src/Command/DaemonCommand.php index 875f6f5..857e338 100644 --- a/src/Command/DaemonCommand.php +++ b/src/Command/DaemonCommand.php @@ -56,7 +56,7 @@ class DaemonCommand extends Command $jobsToRun = $jobRepo->getJobsDue(); if(!empty($jobsToRun)) { - foreach($jobsToRun as $job) { + foreach($jobsToRun as $key=>$job) { if($job->getData('crontype') == 'reboot') { $str = @file_get_contents('/proc/uptime'); $num = floatval($str); @@ -83,6 +83,8 @@ class DaemonCommand extends Command $jobRepo->setJobRunning($job, false); exit; } + unset($jobsToRun[$key]); + unset($job); } } $this->doctrine->getManager()->clear(); @@ -92,6 +94,7 @@ class DaemonCommand extends Command $nextrun = max($jobRepo->getTimeOfNextRun(), time() + 1); $sleepuntil = min($maxwait, $nextrun); if($sleepuntil > time()) time_sleep_until($sleepuntil); + gc_collect_cycles(); } $output->writeln('Ended after ' . $timelimit . ' seconds'); pcntl_wait($status); diff --git a/src/Repository/JobRepository.php b/src/Repository/JobRepository.php index 17e9ac2..bf85027 100644 --- a/src/Repository/JobRepository.php +++ b/src/Repository/JobRepository.php @@ -14,7 +14,6 @@ use GuzzleHttp\Exception\GuzzleException; use phpseclib3\Crypt\PublicKeyLoader; use phpseclib3\Net\SSH2; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\HttpKernelInterface; /** * @@ -108,6 +107,7 @@ class JobRepository extends EntityRepository */ public function getJobsDue(): array { + $this->getEntityManager()->clear(); $qb = $this->createQueryBuilder('job'); return $qb ->where(