File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
packages/queue/src/Driver Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ class DatabaseQueueDriver implements QueueDriverInterface
2424{
2525 use UuidDriverTrait;
2626
27+ protected ?bool $ canSkipLocked = null ;
28+
2729 /**
2830 * DatabaseQueueDriver constructor.
2931 *
@@ -89,6 +91,8 @@ public function pop(?string $channel = null): ?QueueMessage
8991
9092 $ query = $ this ->db ->getQuery (true );
9193
94+ $ do = $ this ->checkCanSkipLocked () ? 'SKIP LOCKED ' : '' ;
95+
9296 $ query ->select ('* ' )
9397 ->from ($ this ->table )
9498 ->where ('channel ' , $ channel )
@@ -100,7 +104,7 @@ function (Query $query) use ($now) {
100104 ->where ('reserved ' , '< ' , $ now ->modify ('- ' . $ this ->timeout . 'seconds ' ));
101105 }
102106 )
103- ->forUpdate ();
107+ ->forUpdate ($ do );
104108
105109 $ data = $ this ->db ->transaction (
106110 function () use ($ now , $ query ) {
@@ -285,4 +289,20 @@ public function disconnect(): static
285289
286290 return $ this ;
287291 }
292+
293+ protected function checkCanSkipLocked (): bool
294+ {
295+ if ($ this ->canSkipLocked !== null ) {
296+ return $ this ->canSkipLocked ;
297+ }
298+
299+ try {
300+ $ this ->db ->createQuery ()->selectRaw ('1 ' )->from ($ this ->table )->forUpdate ('SKIP LOCKED ' )->get ();
301+ $ this ->canSkipLocked = true ;
302+ } catch (Throwable ) {
303+ $ this ->canSkipLocked = false ;
304+ }
305+
306+ return $ this ->canSkipLocked ;
307+ }
288308}
You can’t perform that action at this time.
0 commit comments