/** * */ public function wakeUpFreezedFlows() { //$this->bpmLog('DEBUG', "cron: checking flows with status freezed"); $flowBean = BeanFactory::getBean('pmse_BpmFlow'); $flows = $flowBean->get_list('', "cas_flow_status='FREEZE'"); $n = 0; foreach ($flows['list'] as $flow) { $flowData = get_object_vars($flow); $bean = BeanFactory::getBean($flowData['cas_sugar_module'], $flowData['cas_sugar_object_id']); $caseHandler = new PMSECaseFlowHandler(); $bpmnElement = $caseHandler->retrieveElementByType($flowData['bpmn_type']); $flowRouter = new PMSEFlowRouter(); $executionResult = $bpmnElement->run($flowData, $bean); $executionResult['flow_action'] = 'UPDATE'; $executionResult['flow_id'] = $flowData['id']; $flowRouter->wakeUpEngine($flowData, false, $bean, $executionResult); $n++; } // replace the bpmLog calls for the error handler classes if ($n == 0) { //$this->bpmLog('DEBUG', ": processed $n flows with status freezed"); } else { //$this->bpmLog('INFO', "cron: processed $n flows with status freezed"); } }
/** * * @param type $flowData * @param type $createThread * @param type $bean * @param type $externalAction * @param type $arguments * @return boolean * @codeCoverageIgnore */ public function runEngine($flowData, $createThread = false, $bean = null, $externalAction = '', $arguments = array()) { // Load the bean if the request comes from a RESUME_EXECUTION related origin // like for example: a timer event execution. if (is_null($bean)) { $bean = BeanFactory::retrieveBean($flowData['cas_sugar_module'], $flowData['cas_sugar_object_id']); } // Validating unreferenced elements when cron jobs are executed, after MACAROON-518 shouldn't have // unreferenced elements. This will validate previous records created before this fix. if ($externalAction == 'WAKE_UP') { $elementBean = BeanFactory::getBean('pmse_BpmnEvent', $flowData['bpmn_id']); if (!isset($elementBean->id)) { // Setting active flow to deleted $fd = BeanFactory::getBean('pmse_BpmFlow', $flowData['id']); $fd->cas_flow_status = 'DELETED'; $fd->save(); // Updating process to error $cf = new PMSECaseFlowHandler(); $cf->changeCaseStatus($flowData['cas_id'], 'TERMINATED'); // Exiting without errors return true; } } $preparedData = $this->caseFlowHandler->prepareFlowData($flowData, $createThread); $this->logger->debug("Begin process Element {$flowData['bpmn_type']}"); try { $executionData = $this->processElement($preparedData, $bean, $externalAction, $arguments); if (isset($executionData['process_bean']) && !empty($executionData['process_bean'])) { $bean = $executionData['process_bean']; } $this->validateFailSafes($flowData, $executionData); $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread); } catch (PMSEElementException $e) { $this->logger->warning($e->getMessage()); $element = $e->getElement(); $flow = $e->getFlowData(); $state = empty($flow['id']) ? 'CREATE' : 'UPDATE'; $executionData = $element->prepareResponse($flow, 'ERROR', $state); // If the status is put into error then the Inbox record should be updated as well $this->caseFlowHandler->changeCaseStatus($executionData['flow_data']['cas_id'], 'ERROR'); $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread); } catch (Exception $e) { $this->logger->warning($e->getMessage()); $element = $this->retrievePMSEElement(''); $status = $e->getCode() == 0 ? 'QUEUE' : 'ERROR'; $preparedData['cas_flow_status'] = $status; $executionData = $element->prepareResponse($preparedData, $status, 'CREATE'); // If the status is put into error then the Inbox record should be updated as well if ($status == 'ERROR') { $this->caseFlowHandler->changeCaseStatus($executionData['flow_data']['cas_id'], 'ERROR'); } $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread); } if ($this->caseFlowHandler->numberOfCasesByStatus($flowData, 'ERROR') <= 0 && $externalAction == 'RESUME_EXECUTION') { $this->caseFlowHandler->changeCaseStatus($flowData['cas_id'], 'IN PROGRESS'); } if (!empty($routeData['next_elements'])) { $createThread = sizeof($routeData['next_elements']) > 1; if ($createThread) { $startTime = ($this->maxExecutionTimeout - $this->executionTime) / sizeof($routeData['next_elements']); } foreach ($routeData['next_elements'] as $elementData) { //reset execution time if the derivation is in parallel $this->executionTime = $createThread ? $startTime : $this->executionTime; $this->runEngine($elementData, $createThread, $bean); } } else { // Quick fix to the 0 output printed by some element, // TODO: Don't remove until the fix to the element is commited ob_get_clean(); return true; } return true; }