Very long running jobs were losing the database connection
This commit is contained in:
parent
115b4b74a3
commit
6923152a62
|
@ -125,10 +125,6 @@ class Kernel
|
|||
}
|
||||
|
||||
public function getNewDbCon(): Connection {
|
||||
if(!is_null($this->dbCon)) {
|
||||
$this->dbCon->close();
|
||||
$this->dbCon = null;
|
||||
}
|
||||
$this->dbCon = DriverManager::getConnection(['url' => $_ENV['DATABASE']]);
|
||||
return $this->dbCon;
|
||||
}
|
||||
|
|
|
@ -68,14 +68,13 @@ class DaemonCommand extends Command
|
|||
declare(ticks = 1);
|
||||
pcntl_signal(SIGCHLD, SIG_IGN);
|
||||
$pid = pcntl_fork();
|
||||
$jobRepo = NULL;
|
||||
$jobRepo = new Job($this->kernel->getNewDbCon());
|
||||
$jobRepoFork = new Job($this->kernel->getNewDbCon());
|
||||
if($pid == -1) {
|
||||
$jobRepo->RunJob($job['id'], $job['running'] == 2);
|
||||
$jobRepo->setJobRunning($job['id'], false);
|
||||
$jobRepoFork->RunJob($job['id'], $job['running'] == 2);
|
||||
$jobRepoFork->setJobRunning($job['id'], false);
|
||||
} elseif ($pid == 0) {
|
||||
$jobRepo->RunJob($job['id'], $job['running'] == 2);
|
||||
$jobRepo->setJobRunning($job['id'], false);
|
||||
$jobRepoFork->RunJob($job['id'], $job['running'] == 2);
|
||||
$jobRepoFork->setJobRunning($job['id'], false);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,6 +416,7 @@ class Job extends Repository
|
|||
|
||||
public function runJob(int $job, bool $manual): array
|
||||
{
|
||||
global $kernel;
|
||||
$starttime = microtime(true);
|
||||
$job = $this->getJob($job, true);
|
||||
if ($job['data']['crontype'] == 'http') {
|
||||
|
@ -450,7 +451,8 @@ class Job extends Repository
|
|||
}
|
||||
}
|
||||
// saving to database
|
||||
$runRepo = new Run($this->dbcon);
|
||||
$runRepo = new Run($kernel->getNewDbCon());
|
||||
$this->dbcon = $kernel->getNewDbCon();
|
||||
$runRepo->addRun($job['id'], $result['exitcode'], floor($starttime), $runtime, $result['output'], $flags);
|
||||
if (!$manual){
|
||||
// setting nextrun to next run
|
||||
|
|
Loading…
Reference in New Issue