JobsCommand: stop running after one day or...

...when more than 100MB of memory are still in use after the last job
execution.
This commit is contained in:
Thomas Gelf 2016-06-23 16:11:28 +02:00
parent 3d10e1ba3e
commit 4cdf549afb
1 changed files with 15 additions and 0 deletions

View File

@ -32,8 +32,23 @@ class JobsCommand extends Command
protected function runforever()
{
// We'll terminate ourselves after 24h for now:
$runUnless = time() + 86400;
// We'll exit in case more than 100MB of memory are still in use
// after the last job execution:
$maxMem = 100 * 1024 * 1024;
while (true) {
$this->runAllPendingJobs();
if (memory_get_usage() > $maxMem) {
exit(0);
}
if (time() > $runUnless) {
exit(0);
}
sleep(2);
}
}