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)
7979 */
8080 protected function releaseJobsThatHaveBeenReservedTooLong ($ queue )
8181 {
82- $ expired = Carbon::now ()->subSeconds ($ this ->expire )->getTimestamp ();
82+ $ expiration = Carbon::now ()->subSeconds ($ this ->expire )->getTimestamp ();
83+ $ now = time ();
8384
8485 $ reserved = $ this ->database ->collection ($ this ->table )
8586 ->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 ();
8897
8998 foreach ($ reserved as $ job ) {
9099 $ attempts = $ job ['attempts ' ] + 1 ;
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ public function testQueueJobExpired()
3838
3939 // Expect an attempted older job in the queue
4040 $ job = Queue::pop ('test ' );
41- $ this ->assertEquals (2 , $ job ->getDatabaseJob ()->attempts );
41+ $ this ->assertEquals (1 , $ job ->getDatabaseJob ()->attempts );
4242 $ this ->assertGreaterThan ($ expiry , $ job ->getDatabaseJob ()->reserved_at );
4343
4444 $ job ->delete ();
You can’t perform that action at this time.
0 commit comments