public function launchWorker($queueName) { $instanceManagerModel = new StorkInstanceManagerModel($this->getEntityManager()); $queue = $instanceManagerModel->getQueueInfo($queueName); if ($queue !== NULL) { if (($pid = $queue->getPid()) !== NULL) { $queue->setPid($instanceManagerModel->isExistsPid($pid)); //--- Queue exists but process was killed } if ($queue->getPid() == NULL) { $cwd = getcwd(); $arrayPath = explode(DIRECTORY_SEPARATOR, $cwd); $lastFolder = array_pop($arrayPath); if ($lastFolder == "web") { $arrayPath = array_merge($arrayPath, array('app', 'console')); } else { $arrayPath = array_merge($arrayPath, array($lastFolder, 'app', 'console')); } $phpCommand = 'php ' . implode(DIRECTORY_SEPARATOR, $arrayPath) . ' stork:worker ' . $queueName; $shellCommand = 'nohup ' . $phpCommand . ' > /dev/null 2>&1 & echo $!'; exec($shellCommand, $op); $pid = (int) $op[0]; $queue->setPid($pid); $this->getEntityManager()->persist($queue); $this->getEntityManager()->flush(); } } return 1; }
public function commandTermination($queueName) { $instanceManagerModel = new StorkInstanceManagerModel($this->getEntityManager()); $queueInfo = $instanceManagerModel->getQueueInfo($queueName); if ($queueInfo == NULL) { return NULL; } $pid = $queueInfo->getPid(); if ($pid !== NULL) { $pidOs = $instanceManagerModel->isExistsPid($pid); if ($pidOs == NULL) { $pidOs = ''; } } else { $pidOs = ''; } if (empty($pidOs)) { $queueModel = new StorkQueueModel($this->getEntityManager()); $queueId = $instanceManagerModel->getQueueId($queueName); if ($queueId !== NULL) { $queueModel->clearQueue($queueId); } return $instanceManagerModel->terminateQueue($queueName); } return $instanceManagerModel->changeQueueStatus($queueName, StorkInstanceManager::END); }