protected function setBusyFile()
{
// do not set busy file in debug mode
if ($this->getContainer()->getParameter('kernel.debug')) {
return;
}
// build path
$filesystem = new Filesystem();
$path = $this->getCacheDirectory() . $this->getId() . '.busy';
// init var
$isBusy = false;
// does the busy file already exists.
if ($filesystem->exists($path)) {
$isBusy = true;
// grab counter
$counter = (int) file_get_contents($path);
// check the counter
if ($counter > 9) {
// build class name
$class = 'Backend\\Modules\\' . $this->getModule() . '\\Cronjobs\\' . $this->getAction();
if ($this->getModule() == 'Core') {
$class = 'Backend\\Core\\Cronjobs\\' . $this->getAction();
}
// notify user
throw new BackendException('Cronjob (' . $class . ') is still busy after 10 runs, check it out!');
}
} else {
$counter = 0;
}
// increment counter
++$counter;
// store content
$filesystem->dumpFile($path, $counter);
// if the cronjob is busy we should NOT proceed
if ($isBusy) {
throw new ExitException('The cronjob is still busy');
}
}