Skip to content

Commit

Permalink
Add use for MongoDB\BSON\UTCDateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Apr 27, 2017
1 parent 7a4fc08 commit 07d7fcb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Queue.php
Expand Up @@ -5,6 +5,8 @@

namespace DominionEnterprises\Mongo;

use MongoDB\BSON\UTCDateTime;

/**
* Abstraction of mongo db collection as priority queue.
*
Expand Down Expand Up @@ -155,7 +157,7 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
$pollDurationInMillis = 0;
}

$completeQuery = ['earliestGet' => ['$lte' => new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000))]];
$completeQuery = ['earliestGet' => ['$lte' => new UTCDateTime((int)(microtime(true) * 1000))]];
foreach ($query as $key => $value) {
if (!is_string($key)) {
throw new \InvalidArgumentException('key in $query was not a string');
Expand All @@ -172,7 +174,7 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =

$resetTimestamp = min(max(0, $resetTimestamp * 1000), self::MONGO_INT32_MAX);

$update = ['$set' => ['earliestGet' => new \MongoDB\BSON\UTCDateTime($resetTimestamp)]];
$update = ['$set' => ['earliestGet' => new UTCDateTime($resetTimestamp)]];
$options = ['sort' => ['priority' => 1, 'created' => 1]];

//ints overflow to floats, should be fine
Expand Down Expand Up @@ -231,7 +233,7 @@ public function count(array $query, $running = null)

if ($running === true || $running === false) {
$key = $running ? '$gt' : '$lte';
$totalQuery['earliestGet'] = [$key => new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000))];
$totalQuery['earliestGet'] = [$key => new UTCDateTime((int)(microtime(true) * 1000))];
}

foreach ($query as $key => $value) {
Expand Down Expand Up @@ -318,11 +320,11 @@ public function ackSend(array $message, array $payload, $earliestGet = 0, $prior

$toSet = [
'payload' => $payload,
'earliestGet' => new \MongoDB\BSON\UTCDateTime($earliestGet),
'earliestGet' => new UTCDateTime($earliestGet),
'priority' => $priority,
];
if ($newTimestamp) {
$toSet['created'] = new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000));
$toSet['created'] = new UTCDateTime((int)(microtime(true) * 1000));
}

//using upsert because if no documents found then the doc was removed (SHOULD ONLY HAPPEN BY SOMEONE MANUALLY)
Expand Down Expand Up @@ -385,9 +387,9 @@ public function send(array $payload, $earliestGet = 0, $priority = 0.0)

$message = [
'payload' => $payload,
'earliestGet' => new \MongoDB\BSON\UTCDateTime($earliestGet),
'earliestGet' => new UTCDateTime($earliestGet),
'priority' => $priority,
'created' => new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000)),
'created' => new UTCDateTime((int)(microtime(true) * 1000)),
];

$this->collection->insertOne($message);
Expand Down

0 comments on commit 07d7fcb

Please sign in to comment.