-
Notifications
You must be signed in to change notification settings - Fork 11.5k
[6.x] Use SKIP LOCKED for mysql 8.1 and pgsql 9.5 queue workers #31287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
use SKIP LOCKED for mysql 8.1 and pgsql 9.5 queue workers
- Loading branch information
commit de9c7f39639c3f5981bc6c15e690f58dfadd47f7
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
use Illuminate\Queue\Jobs\DatabaseJob; | ||
use Illuminate\Queue\Jobs\DatabaseJobRecord; | ||
use Illuminate\Support\Carbon; | ||
use PDO; | ||
|
||
class DatabaseQueue extends Queue implements QueueContract | ||
{ | ||
|
@@ -211,7 +212,7 @@ public function pop($queue = null) | |
protected function getNextAvailableJob($queue) | ||
{ | ||
$job = $this->database->table($this->table) | ||
->lockForUpdate() | ||
->lock($this->getLockForPopping()) | ||
->where('queue', $this->getQueue($queue)) | ||
->where(function ($query) { | ||
$this->isAvailable($query); | ||
|
@@ -223,6 +224,24 @@ protected function getNextAvailableJob($queue) | |
return $job ? new DatabaseJobRecord((object) $job) : null; | ||
} | ||
|
||
/** | ||
* Get the lock required for popping the next job. | ||
* | ||
* @return string | ||
< 8000 /td> | */ | |
protected function getLockForPopping() | ||
{ | ||
$databaseEngine = $this->database->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME); | ||
$databaseVersion = $this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); | ||
|
||
if ($databaseEngine == 'mysql' && version_compare($databaseVersion, '8.0.1', '>=') || | ||
$databaseEngine == 'pgsql' && version_compare($databaseVersion, '9.5', '>=')) { | ||
return 'FOR UPDATE SKIP LOCKED'; | ||
} | ||
|
||
return 'FOR UPDATE'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'FOR UPDATE' does not seem to work in MSSQL while not in a cursor. |
||
} | ||
|
||
/** | ||
* Modify the query to check for available jobs. | ||
* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda feels like a hack we need to look at the engine here. Feels like this should be the responsibility of the database component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a hack :)