/** * If the passed item is in a failed state, automatically flag this workflow as having a failed activity * * @param WorkflowHistoryItem $item */ protected function flagActivityFailure(WorkflowHistoryItem $item) { switch ($item->getState()) { case HistoryItemState::FAILED(): case HistoryItemState::TIMED_OUT(): $this->setActivityFailed(); $this->error_messages[] = $item->getErrorMessage(); default: return; } }
public function apply(WorkflowHistory $history) { $item = new WorkflowHistoryItem(); $item->setState(HistoryItemState::SCHEDULED()); $item->setTimeScheduled($this->timestamp); $item->setEventId($this->event_id); $item->setInput($this->getAttribute('input')); $item->setControl($this->getAttribute('control')); $item->setActivityName($this->getAttribute(['activityType', 'name'])); $item->setActivityVersion($this->getAttribute(['activityType', 'version'])); $history->add($item); }
protected function createHistoryItem($name, $version, HistoryItemState $state, $control) { $item = new WorkflowHistoryItem($this->id++); $item->setActivityName($name)->setActivityVersion($version); $item->setTimeScheduled(new \DateTime('2014-10-10 10:01:00')); $item->setTimeStarted(new \DateTime('2014-10-10 10:00:00')); $item->setTimeEnded(new \DateTime('2014-10-10 10:04:00')); $item->setState($state); $item->setControl($control)->setInput($control); return $item; }
public function testActivityFail() { Conf::init(__DIR__ . '/../../../../config/'); $memory_pool = new RedisMemoryPool('decider-tests', 60, Conf::get('redis')); $decider = new Decider(); $decider->setWorkflow(new YamlWorkflow(__DIR__ . '/../Resources/TestSchema.yml')); $decider->setMemoryPool($memory_pool); // Workflow started - $event1 = new DecisionEvent(); $decider->processDecisionEvent($event1); $this->assertCount(1, $event1->getDecision()->getScheduledTasks()); $this->assertEquals(WorkflowResult::COMMAND(), $event1->getDecision()->getWorkflowResult()); $task = $event1->getDecision()->getScheduledTasks()[0]; $this->assertEquals('alpha', $task->getControl()); // Task 1 failed - $alpha = new WorkflowHistoryItem('1'); $alpha->setActivityName('test-activity')->setActivityVersion('1'); $alpha->setTimeScheduled(new \DateTime('2014-10-10 10:01:00')); $alpha->setTimeStarted(new \DateTime('2014-10-10 10:00:00')); $alpha->setTimeEnded(new \DateTime('2014-10-10 10:04:00')); $alpha->setState(HistoryItemState::FAILED()); $alpha->setErrorMessage('Test failure'); $alpha->setControl('alpha')->setInput('alpha')->setResult(">.<"); $event2 = new DecisionEvent(); $event2->getHistory()->add($alpha); $decider->processDecisionEvent($event2); $this->assertCount(0, $event2->getDecision()->getScheduledTasks()); $this->assertEquals(WorkflowResult::FAIL(), $event2->getDecision()->getWorkflowResult()); }
/** * Run the tasks success decider, allowing the task a chance to schedule some events * * @param WorkflowHistoryItem $history_item * @param Decision $decision * @param MemoryPoolInterface $memory_pool */ protected function runTaskDecider(WorkflowHistoryItem $history_item, Decision $decision, MemoryPoolInterface $memory_pool) { foreach ($this->getWorkflow()->getTasks() as $task) { if ($history_item->getActivityName() == $task->getActivityName() && $history_item->getActivityVersion() == $task->getActivityVersion()) { $class = $task->getClass(); /** @var TaskInterface $obj */ $obj = new $class($memory_pool, $history_item->getInput(), $this->getAuxPayload()); if (!$obj instanceof TaskInterface) { throw new \DomainException("Class for task " . $task->getActivityName() . " is not a TaskInterface"); } $obj->onSuccess($this->getWorkflow(), $history_item, $decision); } } }