BUGFIX: mysql could trigger running jobs a lot of times
This commit is contained in:
parent
6923152a62
commit
75ece7ea27
|
@ -125,6 +125,10 @@ class Kernel
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNewDbCon(): Connection {
|
public function getNewDbCon(): Connection {
|
||||||
|
if(!is_null($this->dbCon)) {
|
||||||
|
$this->dbCon->close();
|
||||||
|
$this->dbCon = null;
|
||||||
|
}
|
||||||
$this->dbCon = DriverManager::getConnection(['url' => $_ENV['DATABASE']]);
|
$this->dbCon = DriverManager::getConnection(['url' => $_ENV['DATABASE']]);
|
||||||
return $this->dbCon;
|
return $this->dbCon;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,11 +47,6 @@ class DaemonCommand extends Command
|
||||||
while(1) {
|
while(1) {
|
||||||
if($endofscript !== false && time() > $endofscript) break;
|
if($endofscript !== false && time() > $endofscript) break;
|
||||||
|
|
||||||
$maxwait = time() + 10;
|
|
||||||
$nextrun = $jobRepo->getTimeOfNextRun();
|
|
||||||
$sleepuntil = min($maxwait, $nextrun);
|
|
||||||
if($sleepuntil > time()) time_sleep_until($sleepuntil);
|
|
||||||
|
|
||||||
$jobsToRun = $jobRepo->getJobsDue();
|
$jobsToRun = $jobRepo->getJobsDue();
|
||||||
if(!empty($jobsToRun)) {
|
if(!empty($jobsToRun)) {
|
||||||
foreach($jobsToRun as $job) {
|
foreach($jobsToRun as $job) {
|
||||||
|
@ -68,17 +63,19 @@ class DaemonCommand extends Command
|
||||||
declare(ticks = 1);
|
declare(ticks = 1);
|
||||||
pcntl_signal(SIGCHLD, SIG_IGN);
|
pcntl_signal(SIGCHLD, SIG_IGN);
|
||||||
$pid = pcntl_fork();
|
$pid = pcntl_fork();
|
||||||
$jobRepoFork = new Job($this->kernel->getNewDbCon());
|
$jobRepo = NULL;
|
||||||
|
$jobRepo = new Job($this->kernel->getNewDbCon());
|
||||||
if($pid == -1) {
|
if($pid == -1) {
|
||||||
$jobRepoFork->RunJob($job['id'], $job['running'] == 2);
|
$jobRepo->RunJob($job['id'], $job['running'] == 2);
|
||||||
$jobRepoFork->setJobRunning($job['id'], false);
|
$jobRepo->setJobRunning($job['id'], false);
|
||||||
} elseif ($pid == 0) {
|
} elseif ($pid == 0) {
|
||||||
$jobRepoFork->RunJob($job['id'], $job['running'] == 2);
|
$jobRepo->RunJob($job['id'], $job['running'] == 2);
|
||||||
$jobRepoFork->setJobRunning($job['id'], false);
|
$jobRepo->setJobRunning($job['id'], false);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
$output->writeln('Ended after ' . $timelimit . ' seconds');
|
$output->writeln('Ended after ' . $timelimit . ' seconds');
|
||||||
pcntl_wait($status);
|
pcntl_wait($status);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user