protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { // Get the next scheme action to execute $actionToExecute = \Akzo\Scheme\CommandQueue::getInstance()->getNextSchemeAction(\Akzo\Scheme\Cache\KeyType::EXECUTE); if (empty($actionToExecute) || !isset($actionToExecute[\Akzo\Scheme\ExecuteActionAttribute::CODE])) { return; } $GLOBALS['logger']->info("Got action to execute: " . print_r($actionToExecute, 1)); // FIXME: Read this from the action $groupDealersByCreditCode = true; // Execute the action $result = \Akzo\Scheme\Service::getInstance()->executeScheme($actionToExecute[\Akzo\Scheme\ExecuteActionAttribute::CODE], $actionToExecute[\Akzo\Scheme\ExecuteActionAttribute::TYPE], $groupDealersByCreditCode, $actionToExecute[\Akzo\Scheme\ExecuteActionAttribute::DEALER_OFFSET]); // Check if the scheme has been executed for all dealers if (isset($result['moreDealersLeft']) && $result['moreDealersLeft']) { // If not completed, replay for remaining dealers \Akzo\Scheme\CommandQueue::getInstance()->setSchemeAction($actionToExecute[\Akzo\Scheme\ExecuteActionAttribute::CODE], \Akzo\Scheme\Cache\KeyType::EXECUTE, $actionToExecute[\Akzo\Scheme\ExecuteActionAttribute::TYPE], $result['moreDealersOffset'], \Akzo\Scheme\Cache\ExecuteActionState::WAITING, 0); } else { // If completed, remove Scheme Action \Akzo\Scheme\CommandQueue::getInstance()->removeSchemeAction($actionToExecute[\Akzo\Scheme\ExecuteActionAttribute::CODE], $actionToExecute[\Akzo\Scheme\ExecuteActionAttribute::TYPE], \Akzo\Scheme\Cache\KeyType::EXECUTE); } //// scheme code //$code = $input->getOption(self::OPT_CODE); //// dealer offset //$offset = $input->getOption(self::OPT_OFFSET); //// Start the simulation //$result = \Akzo\Scheme\Service::getInstance()->initiateSimulation($code, $offset); //// Check if the scheme has been executed for all dealers, otherwise replay this command with the new offset //if (isset($result['moreDealersLeft']) && $result['moreDealersLeft']) { //$cmd = 'php '.__DIR__.'/../manageSchemes.php simulate -c '.$code.' -o '.$result['moreDealersOffset']; //// FIXME: Use Symfony Process instead of plain exec ////$process = new \Symfony\Component\Process\Process( ////$cmd ////); ////$process->start(); //if ($offset == 670) { //if (function_exists('xdebug_start_trace')) { //xdebug_start_trace(); //} //$cmd = 'php '.__DIR__.'/../manageSchemesX.php simulate -c '.$code.' -o '.$result['moreDealersOffset']; //} //$GLOBALS['logger']->info("Starting scheme for more dealers from offset ** {$result['moreDealersOffset']} **".PHP_EOL."Command: $cmd"); //$output = array(); $returnVal = 123; //exec($cmd.' >/dev/null 2>&1 &', $output, $returnVal); //$GLOBALS['logger']->info("Got output :".PHP_EOL.print_r($output, 1).PHP_EOL."Return val: ".$returnVal); //} }
public function initiatePDFCreation($schemeId, $executionDataType = \Akzo\Scheme\ExecuteActionDataType::TARGET) { // Load the scheme from the database $this->_checkSchemeCode($schemeId); // Check the status of the simulation of the scheme, if not started start it $result = \Akzo\Scheme\ExecService::getInstance()->checkPDFCreationStatus($schemeId, $executionDataType); // If execution has not started for this scheme and execution type, set an action for it with dealer offset 0 if (strcmp($result['status'], \Akzo\Scheme\ProcessStatus::NOT_STARTED) === 0) { \Akzo\Scheme\CommandQueue::getInstance()->setSchemeAction($schemeId, \Akzo\Scheme\Cache\KeyType::GENERATE_PDF, $executionDataType); $result['status'] = \Akzo\Scheme\ProcessStatus::JUST_STARTED; } return $result; }