public function testTakeRetryPolicyFromRetriableInstance()
 {
     $workable = new WorkableThatUsesRetryStatistics();
     $job = Job::around($workable, $this->repository);
     $job->execute($this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'));
     $this->assertTrue($job->done(), "Job requiring retry statistics was not executed correctly: " . var_export($job->export(), true));
 }
 public function testTakeRetryPolicyFromRetriableInstance()
 {
     $retryPolicy = $this->getMock('Recruiter\\RetryPolicy\\BaseRetryPolicy');
     $retryPolicy->expects($this->once())->method('schedule');
     $workable = new WorkableThatIsAlsoRetriable($retryPolicy);
     $job = Job::around($workable, $this->repository);
     $job->execute($this->eventDispatcher);
 }
 public function testTakeRetryPolicyFromRetriableInstance()
 {
     $listener = $this->getMock('StdClass', ['onEvent']);
     $listener->expects($this->exactly(3))->method('onEvent')->withConsecutive([$this->equalTo('job.started'), $this->anything()], [$this->equalTo('job.ended'), $this->anything()], [$this->equalTo('job.failure.last'), $this->anything()]);
     $workable = new WorkableThatIsAlsoAnEventListener($listener);
     $job = Job::around($workable, $this->repository);
     $job->execute($this->dispatcher);
 }
Beispiel #4
0
 /**
  * @step
  */
 public function bookJobsForWorkers()
 {
     $roster = $this->db->selectCollection('roster');
     $scheduled = $this->db->selectCollection('scheduled');
     $workersPerUnit = 42;
     $bookedJobs = [];
     foreach (Worker::pickAvailableWorkers($roster, $workersPerUnit) as $resultRow) {
         list($worksOn, $workers) = $resultRow;
         $result = Job::pickReadyJobsForWorkers($scheduled, $worksOn, $workers);
         if ($result) {
             list($worksOn, $workers, $jobs) = $result;
             list($assignments, $jobs, $workers) = $this->combineJobsWithWorkers($jobs, $workers);
             Job::lockAll($scheduled, $jobs);
             $bookedJobs[] = [$jobs, $workers];
         }
     }
     return $bookedJobs;
 }
Beispiel #5
0
 private function aJob()
 {
     $workable = $this->getMockBuilder('Recruiter\\Workable')->getMock();
     return Job::around($workable, $this->repository)->scheduleAt(T\now()->before(T\seconds(5)));
 }
Beispiel #6
0
 private function map($cursor)
 {
     $jobs = [];
     while ($cursor->hasNext()) {
         $jobs[] = Job::import($cursor->getNext(), $this);
     }
     return $jobs;
 }