diff --git a/Command/ScheduleCommand.php b/Command/ScheduleCommand.php index fa6fe57a..f11cdadb 100644 --- a/Command/ScheduleCommand.php +++ b/Command/ScheduleCommand.php @@ -52,7 +52,9 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - $jobsLastRunAt = $this->populateJobsLastRunAt($registry->getManagerForClass(CronJob::class), $jobSchedulers); + /** @var \Doctrine\ORM\EntityManager $em */ + $em = $registry->getManagerForClass(CronJob::class); + $jobsLastRunAt = $this->populateJobsLastRunAt($em, $jobSchedulers); $startedAt = time(); while (true) { @@ -63,6 +65,11 @@ protected function execute(InputInterface $input, OutputInterface $output) break; } + if ($em->getConnection()->ping() === false) { + $em->getConnection()->close(); + $em->getConnection()->connect(); + } + $this->scheduleJobs($output, $registry, $jobSchedulers, $jobsLastRunAt); $timeToWait = microtime(true) - $lastRunAt + $minJobInterval;