Example #1
0
 /**
  * Check if the given task meets its schedule requirements
  *
  * @param TaskSchema $task
  * @return bool
  */
 public function canScheduleTask(TaskSchema $task)
 {
     // Don't schedule again if this task has already been scheduled
     if ($this->history_inspector->hasTaskBeenScheduled($task)) {
         return false;
     }
     $requirements = $task->getRequires();
     if (!is_array($requirements) || count($requirements) == 0) {
         // No requirements, schedule away!
         return true;
     }
     // Check against every other type of requirement
     return $this->meetsActivityRequirements($this->getRequirementBlock($requirements, 'activity')) && $this->meetsControlRequirements($this->getRequirementBlock($requirements, 'control')) && $this->meetsVariableRequirements($this->getRequirementBlock($requirements, 'variable'));
 }
Example #2
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));
 }