Skip to content

Commit 1512507

Browse files
committed
fix all jobs attempts incremented
- apply pr 1855 to v3.3.1 for laravel 5.5 - mongodb#1855
1 parent 5454ac9 commit 1512507

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/Jenssegers/Mongodb/Queue/MongoQueue.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ protected function getNextAvailableJobAndReserve($queue)
7070
$job = $this->database->getCollection($this->table)->findOneAndUpdate(
7171
[
7272
'queue' => $this->getQueue($queue),
73-
'reserved' => 0,
73+
'reserved' => ['$ne' => 1],
7474
'available_at' => ['$lte' => Carbon::now()->getTimestamp()],
7575
],
7676
[
7777
'$set' => [
7878
'reserved' => 1,
7979
'reserved_at' => Carbon::now()->getTimestamp(),
8080
],
81+
'$inc' => [
82+
'attempts' => 1,
83+
],
8184
],
8285
[
8386
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
@@ -101,24 +104,15 @@ protected function getNextAvailableJobAndReserve($queue)
101104
protected function releaseJobsThatHaveBeenReservedTooLong($queue)
102105
{
103106
$expiration = Carbon::now()->subSeconds($this->retryAfter)->getTimestamp();
104-
$now = time();
105107

106108
$reserved = $this->database->collection($this->table)
107109
->where('queue', $this->getQueue($queue))
108-
->where(function ($query) use ($expiration, $now) {
109-
// Check for available jobs
110-
$query->where(function ($query) use ($now) {
111-
$query->whereNull('reserved_at');
112-
$query->where('available_at', '<=', $now);
113-
});
114-
115-
// Check for jobs that are reserved but have expired
116-
$query->orWhere('reserved_at', '<=', $expiration);
117-
})->get();
110+
->whereNotNull('reserved_at')
111+
->where('reserved_at', '<=', $expiration)
112+
->get();
118113

119114
foreach ($reserved as $job) {
120-
$attempts = $job['attempts'] + 1;
121-
$this->releaseJob($job['_id'], $attempts);
115+
$this->releaseJob($job['_id'], $job['attempts']);
122116
}
123117
}
124118

@@ -145,4 +139,4 @@ public function deleteReserved($queue, $id)
145139
{
146140
$this->database->collection($this->table)->where('_id', $id)->delete();
147141
}
148-
}
142+
}

0 commit comments

Comments
 (0)