Exemple #1
0
 public function testShouldRescheduleInOneMinuteWhenWasCreatedLessThanFiveMinutesAgo()
 {
     $expectedToBeScheduledAt = T\minute(1)->fromNow()->toSecondPrecision();
     $wasCreatedAt = T\seconds(10)->ago();
     $job = $this->givenJobThat($wasCreatedAt);
     $job->expects($this->once())->method('scheduleAt')->with($this->equalTo($expectedToBeScheduledAt));
     $this->scheduler->schedule($job);
 }
Exemple #2
0
 public function recentHistory($group = null, T\Moment $at = null, array $query = [])
 {
     if ($at === null) {
         $at = T\now();
     }
     $lastMinute = array_merge($query, ['last_execution.ended_at' => ['$gt' => T\MongoDate::from($at->before(T\minute(1))), '$lte' => T\MongoDate::from($at)]]);
     if ($group !== null) {
         $lastMinute['group'] = $group;
     }
     $document = $this->archived->aggregate($pipeline = [['$match' => $lastMinute], ['$project' => ['latency' => ['$subtract' => ['$last_execution.started_at', '$last_execution.scheduled_at']], 'execution_time' => ['$subtract' => ['$last_execution.ended_at', '$last_execution.started_at']]]], ['$group' => ['_id' => 1, 'throughput' => ['$sum' => 1], 'latency' => ['$avg' => '$latency'], 'execution_time' => ['$avg' => '$execution_time']]]]);
     if (!$document['ok']) {
         throw new RuntimeException("Pipeline failed: " . var_export($pipeline, true));
     }
     if (count($document['result']) === 0) {
         $throughputPerMinute = 0.0;
         $averageLatency = 0.0;
         $averageExecutionTime = 0;
     } else {
         if (count($document['result']) === 1) {
             $throughputPerMinute = (double) $document['result'][0]['throughput'];
             $averageLatency = $document['result'][0]['latency'] / 1000;
             $averageExecutionTime = $document['result'][0]['execution_time'] / 1000;
         } else {
             throw new RuntimeException("Result was not ok: " . var_export($document, true));
         }
     }
     return ['throughput' => ['value' => $throughputPerMinute, 'value_per_second' => $throughputPerMinute / 60.0], 'latency' => ['average' => $averageLatency], 'execution_time' => ['average' => $averageExecutionTime]];
 }