Example #1
0
 private function inflate()
 {
     Registry::PhlowLog()->addInfo('Inflating');
     $this->workflowName = $this->raw['workflowType']['name'];
     $this->workflowVersion = $this->raw['workflowType']['version'];
     $this->workflowRunId = $this->raw['workflowExecution']['runId'];
     $this->workflowId = $this->raw['workflowExecution']['workflowId'];
     $this->token = $this->raw['taskToken'];
     $this->previousStartedEventId = $this->raw['previousStartedEventId'];
     $this->startedEventId = $this->raw['startedEventId'];
     foreach ($this->raw['events'] as $raw_event) {
         switch ($raw_event['eventType']) {
             case EventType::WORKFLOW_EXECUTION_STARTED:
                 $event = new \Phlow\Events\WorkflowExecutionStarted($raw_event);
                 $this->eventManager->setExecutionEvent($event);
                 $this->eventManager->setLastEvent($event);
                 break;
             case EventType::ACTIVITY_TASK_COMPLETED:
                 $event = new \Phlow\Events\ActivityTaskCompleted($raw_event);
                 $this->eventManager->setLastEvent($event);
                 break;
             case EventType::ACTIVITY_TASK_FAILED:
                 $event = new \Phlow\Events\ActivityTaskFailed($raw_event);
                 $this->eventManager->setLastEvent($event);
                 break;
             case EventType::ACTIVITY_TASK_SCHEDULED:
                 $event = new \Phlow\Events\ActivityTaskScheduled($raw_event);
                 break;
             case EventType::ACTIVITY_TASK_STARTED:
                 $event = new \Phlow\Events\ActivityTaskStarted($raw_event);
                 break;
             case EventType::WORKFLOW_EXECUTION_SIGNALED:
                 $event = new \Phlow\Events\WorkflowExecutionSignaled($raw_event);
                 break;
             case EventType::TIMER_STARTED:
                 $event = new \Phlow\Events\TimerStarted($raw_event);
                 break;
             default:
                 $event = new \Phlow\Events\BaseEvent($raw_event);
         }
         $this->eventManager->addEvent($event);
     }
     $this->eventManager->buildOptionData();
 }
Example #2
0
 /**
  * Waits for an activity task to come in from SWF and directs it to the appropriate handler
  */
 public function pollForTasks()
 {
     while (true) {
         try {
             $taskData = $this->swfClient->pollForActivityTask(array('domain' => $this->domain, 'taskList' => array("name" => $this->taskList), 'identity' => get_class() . '-' . microtime()));
         } catch (Exception $e) {
             var_dump($e);
             die('here');
         }
         if ($taskData['taskToken']) {
             $task = new Task($taskData->toArray());
             Registry::PhlowLog()->addInfo('Trying to process request');
             try {
                 $results = $this->handler->handle($this->swfClient, $task);
                 Registry::PhlowLog()->addInfo('Task Handled successfully');
                 $this->swfClient->respondActivityTaskCompleted(array('taskToken' => $task->getToken(), 'result' => base64_encode(json_encode($results))));
             } catch (\Exception $e) {
                 Registry::PhlowLog()->addInfo('There was a problem handling this Task');
                 $this->swfClient->respondActivityTaskFailed(array('taskToken' => $task->getToken(), 'reason' => $e->getMessage()));
             }
         }
     }
 }
Example #3
0
 /**
  * Waits for a decision task to come in from SWF and determines what the next action should be
  */
 public function pollForTasks()
 {
     while (true) {
         try {
             $taskData = $this->swfClient->pollForDecisionTask(array('domain' => $this->domain, 'taskList' => array("name" => $this->taskList), 'identity' => $this->identity, 'reverseOrder' => true));
         } catch (Exception $e) {
             var_dump($e);
             die('here');
         }
         if ($taskData['taskToken']) {
             $this->job = new Job($taskData->toArray());
             // @todo Move this out to another function/class
             $lastEvent = $this->job->getEventManager()->getLastEvent();
             switch ($lastEvent->getType()) {
                 case EventType::TIMER_FIRED:
                     $this->addDecision($this->loadTask($this->job->getEventManager()->getExecutionEvent()->getFlow()));
                     break;
                 case EventType::WORKFLOW_EXECUTION_STARTED:
                     $this->addDecision($this->loadTask($this->job->getEventManager()->getExecutionEvent()->getFlow()));
                     break;
                 case EventType::WORKFLOW_EXECUTION_SIGNALED:
                     Registry::PhlowLog()->addInfo("Received Signal {$lastEvent->getName()}");
                     $this->addDecision(array('decisionType' => DecisionType::RECORD_MARKER, 'recordMarkerDecisionAttributes' => array('markerName' => 'Signal', 'details' => "Incoming Signal of type {$lastEvent->getName()}")));
                     break;
                 case EventType::ACTIVITY_TASK_COMPLETED:
                     $eventCaller = $this->job->getEventManager()->getEvent($lastEvent->getScheduledEventId());
                     Registry::PhlowLog()->addInfo("Task Completed: {$eventCaller->getId()}");
                     $lastStep = $eventCaller->getControl();
                     // @todo Look at this and make a bit more robust
                     $nextStep = $lastStep * 1 + 1;
                     if ($nextStep <= sizeof($this->job->getEventManager()->getExecutionEvent()->getFlow()['steps'])) {
                         $this->addDecision($this->loadTask($this->job->getEventManager()->getExecutionEvent()->getFlow(), "" . $nextStep));
                     } else {
                         Registry::PhlowLog()->addInfo("Task Completed: {$eventCaller->getType()}");
                         $this->addDecision(array('decisionType' => DecisionType::COMPLETE_WORKFLOW_EXECUTION, 'completeWorkflowExecutionDecisionAttributes' => array('result' => 'FINAL RESULTS')));
                     }
                     break;
                 default:
                     // Do nothing
                     $this->addDecision(array('decisionType' => DecisionType::FAIL_WORKFLOW_EXECUTION, 'failWorkflowExecutionDecisionAttributes' => array('reason' => 'Error')));
             }
             if (sizeof($this->decisions) > 0) {
                 $this->swfClient->respondDecisionTaskCompleted(array('taskToken' => $this->job->getToken(), 'decisions' => $this->decisions));
                 $this->decisions = array();
             } else {
                 Registry::PhlowLog()->addInfo('Not responding with task completed');
             }
         }
     }
 }