Commit 76281c1b authored by Pooya Parsa's avatar Pooya Parsa

queue tests

parent 65fd2543
...@@ -79,12 +79,21 @@ class MongoQueue extends DatabaseQueue ...@@ -79,12 +79,21 @@ class MongoQueue extends DatabaseQueue
*/ */
protected function releaseJobsThatHaveBeenReservedTooLong($queue) protected function releaseJobsThatHaveBeenReservedTooLong($queue)
{ {
$expired = Carbon::now()->subSeconds($this->expire)->getTimestamp(); $expiration = Carbon::now()->subSeconds($this->expire)->getTimestamp();
$now = time();
$reserved = $this->database->collection($this->table) $reserved = $this->database->collection($this->table)
->where('queue', $this->getQueue($queue)) ->where('queue', $this->getQueue($queue))
->where('reserved', 1) ->where(function ($query) use ($expiration, $now) {
->where('reserved_at', '<=', $expired)->get(); // Check for available jobs
$query->where(function ($query) use ($now) {
$query->whereNull('reserved_at');
$query->where('available_at', '<=', $now);
});
// Check for jobs that are reserved but have expired
$query->orWhere('reserved_at', '<=', $expiration);
})->get();
foreach ($reserved as $job) { foreach ($reserved as $job) {
$attempts = $job['attempts'] + 1; $attempts = $job['attempts'] + 1;
......
...@@ -38,7 +38,7 @@ class QueueTest extends TestCase ...@@ -38,7 +38,7 @@ class QueueTest extends TestCase
// Expect an attempted older job in the queue // Expect an attempted older job in the queue
$job = Queue::pop('test'); $job = Queue::pop('test');
$this->assertEquals(2, $job->getDatabaseJob()->attempts); $this->assertEquals(1, $job->getDatabaseJob()->attempts);
$this->assertGreaterThan($expiry, $job->getDatabaseJob()->reserved_at); $this->assertGreaterThan($expiry, $job->getDatabaseJob()->reserved_at);
$job->delete(); $job->delete();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment