public function apply(WorkflowHistory $history)
 {
     $activity = $this->getAttribute(['activityType', 'name']) . '-' . $this->getAttribute(['activityType', 'version']);
     $cause = $this->getAttribute('cause');
     $history->setActivityFailed();
     $history->setWorkflowFailed('Unable to schedule activity task: ' . $activity . ' (' . $cause . ')');
 }
 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);
 }
 public function apply(WorkflowHistory $history)
 {
     $reason = $this->getAttribute('reason');
     if ($details = $this->getAttribute('details', null)) {
         $reason .= ' (' . $details . ')';
     }
     if ($cause = $this->getAttribute('cause', null)) {
         $reason .= ' (Cause: ' . $cause . ')';
     }
     $history->setTimeEnded($this->timestamp);
     $history->setWorkflowFailed('Terminated: ' . $reason);
 }
 public function testCommand()
 {
     $timestamp = 1326670266.115;
     $datestamp = new \DateTime();
     $datestamp->setTimestamp($timestamp);
     $attributes = ['reason' => 'Gremlins'];
     $event_id = 'test_' . rand(10000, 99999);
     $history = new WorkflowHistory();
     $command = new WorkflowExecutionFailedCommand($datestamp, $attributes, $event_id);
     $this->assertFalse($history->hasWorkflowFailed());
     $this->assertNull($history->getTimeStarted());
     $this->assertNull($history->getInput());
     $command->apply($history);
     $this->assertTrue($history->hasWorkflowFailed());
     $this->assertEquals('1326670266', $history->getTimeEnded()->format('U'));
     $this->assertEquals('Failed: Gremlins', $history->getErrorMessages()[0]);
 }
 public function testCommand()
 {
     $timestamp = 1326670266.115;
     $datestamp = new \DateTime();
     $datestamp->setTimestamp($timestamp);
     $attributes = ['activityType' => ['name' => 'TestActivity', 'version' => 123], 'cause' => 'Gremlins'];
     $event_id = 'test_' . rand(10000, 99999);
     $history = new WorkflowHistory();
     $command = new ScheduleActivityTaskFailedCommand($datestamp, $attributes, $event_id);
     $this->assertFalse($history->hasWorkflowFailed());
     $this->assertNull($history->getTimeStarted());
     $this->assertNull($history->getInput());
     $command->apply($history);
     // When a schedule fails, we should mark the workflow as critically failed, but it still hasn't ended
     // This should act as an indication to fail the entire workflow
     $this->assertTrue($history->hasWorkflowFailed());
     $this->assertNull($history->getTimeEnded());
     $this->assertEquals('Unable to schedule activity task: TestActivity-123 (Gremlins)', $history->getErrorMessages()[0]);
 }
 public function testCounts()
 {
     $history = new WorkflowHistory();
     $history->add($this->createHistoryItem('test-activity', '1', HistoryItemState::COMPLETED(), 'alpha'));
     $history->add($this->createHistoryItem('test-activity', '1', HistoryItemState::COMPLETED(), 'bravo'));
     $history->add($this->createHistoryItem('test-activity', '2', HistoryItemState::COMPLETED(), 'charlie'));
     $history->add($this->createHistoryItem('test-activity', '1', HistoryItemState::SCHEDULED(), 'delta'));
     $history->add($this->createHistoryItem('other-activity', '1', HistoryItemState::COMPLETED(), 'echo'));
     $history->add($this->createHistoryItem('other-activity', '1', HistoryItemState::RUNNING(), 'foxtrot'));
     $inspector = new HistoryInspector($history);
     $schema_test = TaskSchema::fromKey('test-activity/1');
     $schema_other = TaskSchema::fromKey('other-activity/1');
     $this->assertEquals(0, $inspector->countTask($schema_test, HistoryItemState::RUNNING()));
     $this->assertEquals(0, $inspector->countTask($schema_test, HistoryItemState::FAILED()));
     $this->assertEquals(2, $inspector->countTask($schema_test, HistoryItemState::COMPLETED()));
     $this->assertEquals(1, $inspector->countTask($schema_test, HistoryItemState::SCHEDULED()));
     $this->assertEquals(1, $inspector->countTask($schema_other, HistoryItemState::COMPLETED()));
     $this->assertEquals(1, $inspector->countTask($schema_other, HistoryItemState::RUNNING()));
     $this->assertEquals(0, $inspector->countTask($schema_other, HistoryItemState::SCHEDULED()));
     $this->assertEquals(0, $inspector->countTask($schema_other, HistoryItemState::FAILED()));
     $this->assertEquals(1, $inspector->countControl('alpha', HistoryItemState::COMPLETED()));
     $this->assertEquals(1, $inspector->countControl('bravo', HistoryItemState::COMPLETED()));
     $this->assertEquals(1, $inspector->countControl('charlie', HistoryItemState::COMPLETED()));
     $this->assertEquals(0, $inspector->countControl('delta', HistoryItemState::COMPLETED()));
     $this->assertEquals(1, $inspector->countControl('echo', HistoryItemState::COMPLETED()));
     $this->assertEquals(0, $inspector->countControl('foxtrot', HistoryItemState::COMPLETED()));
     $this->assertTrue($inspector->haveOpenActivities());
     $alpha = new TaskSchema();
     $alpha->setActivityName('test-activity')->setActivityVersion('1')->setControl('alpha');
     $this->assertEquals(2, $inspector->countTask($alpha, HistoryItemState::COMPLETED()));
     $this->assertEquals(1, $inspector->countTask($alpha, HistoryItemState::SCHEDULED()));
     $omega = new TaskSchema();
     $omega->setActivityName('test-activity')->setActivityVersion('10');
     $this->assertEquals(0, $inspector->countTask($omega, HistoryItemState::COMPLETED()));
     $this->assertTrue($inspector->hasTaskBeenScheduled($alpha));
     $this->assertFalse($inspector->hasTaskBeenScheduled($omega));
 }
 public function apply(WorkflowHistory $history)
 {
     $history->setInput($this->getAttribute('input'));
     $history->setTimeStarted($this->timestamp);
 }
 public function apply(WorkflowHistory $history)
 {
     $history->setTimeEnded($this->timestamp);
 }
 public function apply(WorkflowHistory $history)
 {
     $history->setTimeEnded($this->timestamp);
     $history->setWorkflowFailed('Cancelled: ' . $this->getAttribute('details'));
 }
 public function apply(WorkflowHistory $history)
 {
     $history->setTimeEnded($this->timestamp);
     $history->setWorkflowFailed('Timeout: ' . $this->getAttribute('timeoutType'));
 }