File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
src/Jenssegers/Mongodb/Queue Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -79,12 +79,21 @@ protected function getNextAvailableJobAndReserve($queue)
79
79
*/
80
80
protected function releaseJobsThatHaveBeenReservedTooLong ($ queue )
81
81
{
82
- $ expired = Carbon::now ()->subSeconds ($ this ->expire )->getTimestamp ();
82
+ $ expiration = Carbon::now ()->subSeconds ($ this ->expire )->getTimestamp ();
83
+ $ now = time ();
83
84
84
85
$ reserved = $ this ->database ->collection ($ this ->table )
85
86
->where ('queue ' , $ this ->getQueue ($ queue ))
86
- ->where ('reserved ' , 1 )
87
- ->where ('reserved_at ' , '<= ' , $ expired )->get ();
87
+ ->where (function ($ query ) use ($ expiration , $ now ) {
88
+ // Check for available jobs
89
+ $ query ->where (function ($ query ) use ($ now ) {
90
+ $ query ->whereNull ('reserved_at ' );
91
+ $ query ->where ('available_at ' , '<= ' , $ now );
92
+ });
93
+
94
+ // Check for jobs that are reserved but have expired
95
+ $ query ->orWhere ('reserved_at ' , '<= ' , $ expiration );
96
+ })->get ();
88
97
89
98
foreach ($ reserved as $ job ) {
90
99
$ attempts = $ job ['attempts ' ] + 1 ;
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ public function testQueueJobExpired()
38
38
39
39
// Expect an attempted older job in the queue
40
40
$ job = Queue::pop ('test ' );
41
- $ this ->assertEquals (2 , $ job ->getDatabaseJob ()->attempts );
41
+ $ this ->assertEquals (1 , $ job ->getDatabaseJob ()->attempts );
42
42
$ this ->assertGreaterThan ($ expiry , $ job ->getDatabaseJob ()->reserved_at );
43
43
44
44
$ job ->delete ();
You can’t perform that action at this time.
0 commit comments