1
0
Fork 0

Return JSON report for cron calls

master
Anonymous Contributor 2023-09-10 11:58:20 +02:00
parent e6ba73430b
commit a166e65421
1 changed files with 7 additions and 1 deletions

View File

@ -27,6 +27,7 @@ class CronStarter extends RequestHandler
$jobRuns[$row['Name']] = $row['LastRun'];
}
$resArray = [];
$cronUpdateStatement = $this->app->db()->prepare('REPLACE INTO mcp_cron_runs(Name,LastRun) VALUES (?,?)');
foreach ($cronJobs as $jobName) {
$jobClass = "Mcp\\Cron\\".$jobName;
@ -35,10 +36,15 @@ class CronStarter extends RequestHandler
$now = time();
$nextRun = $job->getNextRun(isset($jobRuns[$jobName]) ? $jobRuns[$jobName] : $now - 60);
if ($now >= $nextRun && $job->run()) {
error_log($now.' <= '.$nextRun);
$cronUpdateStatement->execute([$jobName, time()]);
$resArray[$jobName] = ['result' => 'ok', 'nextRun' => $job->getNextRun(time())];
}
else {
$resArray[$jobName] = ['result' => 'failed'];
}
}
}
echo json_encode($resArray);
}
}