Ejemplo n.º 1
0
 public function testConvertsBackAndForthMongoDatesWithoutLosingMillisecondPrecision()
 {
     $this->forAll(Generator\choose(0, 1500 * 1000 * 1000))->then(function ($milliseconds) {
         $moment = new Moment($milliseconds);
         $this->assertEquals($moment, MongoDate::toMoment(MongoDate::from($moment)));
     });
 }
Ejemplo n.º 2
0
 public function export()
 {
     $exported = [];
     if ($this->scheduledAt) {
         $exported['scheduled_at'] = T\MongoDate::from($this->scheduledAt);
     }
     if ($this->startedAt) {
         $exported['started_at'] = T\MongoDate::from($this->startedAt);
     }
     if ($this->endedAt) {
         $exported['ended_at'] = T\MongoDate::from($this->endedAt);
     }
     if ($this->failedWith) {
         $exported['class'] = get_class($this->failedWith);
         $exported['message'] = $this->failedWith->getMessage();
         $exported['trace'] = $this->traceOf($this->failedWith);
     }
     if ($this->completedWith) {
         $exported['trace'] = $this->traceOf($this->completedWith);
     }
     if ($exported) {
         return ['last_execution' => $exported];
     } else {
         return [];
     }
 }
Ejemplo n.º 3
0
 public function scheduleAt(Moment $at)
 {
     $this->status['locked'] = false;
     $this->status['scheduled_at'] = T\MongoDate::from($at);
     return $this;
 }
Ejemplo n.º 4
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]];
 }