Cleanup does not include cron.pid
Closed this issue · 3 comments
When the module runs initialize(), it does this:
$this->setPid('cron.pid',$pid);
The following is then called:
public function setPid($file,$scheduleid) {
#print 'file='.$file;
file_put_contents(self::VAR_FOLDER_PATH.'/cron/'.$file,$scheduleid);
}
At this point, we have a file of var/cron/cron.pid
with the PID in it.
Later, there is a function called cleanupProcesses():
public function cleanupProcesses() {
$running = array();
$pids = $this->getRunningPids();
foreach ($pids as $pid=>$scheduleid) {
if (!$this->checkProcess($pid)) {
$this->unsetPid('cron.'.$pid);
$this->resource->resetSchedule();
} else {
array_push($running,$pid);
}
}
$this->runningPids = $running;
}
This runs getRunningPids():
public function getRunningPids() {
$pids = array();
$filelist = scandir(self::VAR_FOLDER_PATH.'/cron/');
foreach ($filelist as $file) {
if ($file != 'cron.pid') {
$pid = str_replace('cron.','',$file);
if (is_numeric($pid)) {
$pids[$pid] = file_get_contents(self::VAR_FOLDER_PATH.'/cron/'.$file);
}
}
}
return $pids;
}
While the $pids
array is being built, the cron.pid
file is skipped:
public function unsetPid($pid) {
$pidfile = self::VAR_FOLDER_PATH.'/cron/'.$pid;
if(file_exists($pidfile)) {
unlink($pidfile);
}
}
This leaves the cron.pid
file on the server indefinitely. Is there a reason for this?
This is by design and necessary for the cron to function, the pid is for the php process that runs the service, this file should always exist.
@gnuzealot so the file should never receive a new PID, and should just remain as it was created indefinitely, keeping the same PID after the process has terminated? We're analyzing the module as we've run into a number of issues while using it, and this felt odd so we wanted to check. Additionally, if we manually remove this file, it is regenerated by the module.
@gnuzealot can you confirm that if cron.pid disappears for any reason, that the cron server on your end (the one that we don't have access to) would not spin up any additional processes, causing there to be duplicates? Just confirming a few more things.
The piece we're looking into is that we are having duplicate jobs scheduled, and while the module does mark one of them as missed, it still runs. This has only occurred since implementing this module.
This job is specifically related to an Xtento module, and they specifically reference your module here: https://support.xtento.com/wiki/Setting_up_the_Magento_cronjob_(Magento_2), saying:
Using the MageMojo_Cron module? Disabling it has helped other customers in the past. We're working with MageMojo to figure out what's wrong.
It would be great to have insight into what's going on there.
Thanks!