Skip to content

Commit 99bb398

Browse files
authored
Merge pull request #49 from chadicus/master
Use milliseconds for earliestGet in ackSend()
2 parents d5e9616 + 67494ba commit 99bb398

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Queue.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
157157

158158
//reset stuck messages
159159
$this->collection->updateMany(
160-
['running' => true, 'resetTimestamp' => ['$lte' => new \MongoDB\BSON\UTCDateTime(microtime(true) * 1000)]],
160+
['running' => true, 'resetTimestamp' => ['$lte' => new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000))]],
161161
['$set' => ['running' => false]]
162162
);
163163

@@ -170,7 +170,7 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
170170
$completeQuery["payload.{$key}"] = $value;
171171
}
172172

173-
$completeQuery['earliestGet'] = ['$lte' => new \MongoDB\BSON\UTCDateTime(microtime(true) * 1000)];
173+
$completeQuery['earliestGet'] = ['$lte' => new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000))];
174174

175175
$resetTimestamp = time() + $runningResetDuration;
176176
//ints overflow to floats
@@ -319,7 +319,7 @@ public function ackSend(array $message, array $payload, $earliestGet = 0, $prior
319319
}
320320

321321
//Ensure $earliestGet is between 0 and MONGO_INT32_MAX
322-
$earliestGet = min(max(0, $earliestGet), self::MONGO_INT32_MAX);
322+
$earliestGet = min(max(0, $earliestGet * 1000), self::MONGO_INT32_MAX);
323323

324324
$toSet = [
325325
'payload' => $payload,
@@ -329,7 +329,7 @@ public function ackSend(array $message, array $payload, $earliestGet = 0, $prior
329329
'priority' => $priority,
330330
];
331331
if ($newTimestamp) {
332-
$toSet['created'] = new \MongoDB\BSON\UTCDateTime(microtime(true) * 1000);
332+
$toSet['created'] = new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000));
333333
}
334334

335335
//using upsert because if no documents found then the doc was removed (SHOULD ONLY HAPPEN BY SOMEONE MANUALLY)
@@ -396,7 +396,7 @@ public function send(array $payload, $earliestGet = 0, $priority = 0.0)
396396
'resetTimestamp' => new \MongoDB\BSON\UTCDateTime(self::MONGO_INT32_MAX * 1000),
397397
'earliestGet' => new \MongoDB\BSON\UTCDateTime($earliestGet * 1000),
398398
'priority' => $priority,
399-
'created' => new \MongoDB\BSON\UTCDateTime(microtime(true) * 1000),
399+
'created' => new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000)),
400400
];
401401

402402
$this->collection->insertOne($message);

tests/QueueTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ public function resetStuck()
482482
//sets to running
483483
$this->collection->updateOne(
484484
['payload.key' => 0],
485-
['$set' => ['running' => true, 'resetTimestamp' => new \MongoDB\BSON\UTCDateTime(microtime(true) * 1000)]]
485+
['$set' => ['running' => true, 'resetTimestamp' => new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000))]]
486486
);
487487
$this->collection->updateOne(
488488
['payload.key' => 1],
489-
['$set' => ['running' => true, 'resetTimestamp' => new \MongoDB\BSON\UTCDateTime(microtime(true) * 1000)]]
489+
['$set' => ['running' => true, 'resetTimestamp' => new \MongoDB\BSON\UTCDateTime((int)(microtime(true) * 1000))]]
490490
);
491491

492492
$this->assertSame(2, $this->collection->count(['running' => true]));

0 commit comments

Comments
 (0)