public function queue(StorkCommandInstance $commandInstance, $queueName, $launcherExecute = TRUE) { $instanceManagerModel = new StorkInstanceManagerModel($this->getEntityManager()); $queueModel = new StorkQueueModel($this->getEntityManager()); if ($instanceManagerModel->queueExists($queueName) == FALSE) { $queueIdNew = $instanceManagerModel->createNewQueue($queueName); $queueId = $instanceManagerModel->getQueueId($queueName); if ($queueIdNew !== $queueId) { throw new \Exception("Cannot create new queue"); } } else { $queueId = $instanceManagerModel->getQueueId($queueName); } if ($queueId == NULL) { throw new \Exception("Cannot find queue: {$queueName}"); } $hashCommand = $queueModel->getHashCommand($commandInstance, $queueId); if ($queueModel->hashCommandExists($hashCommand) == FALSE) { $commandId = $queueModel->pushCommandToQueue($commandInstance, $queueId); if ($launcherExecute == TRUE) { $this->launchWorker($queueName); } return $commandId; } else { return 0; } return NULL; }
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); }