Skip to content

Commit

Permalink
Update DatabaseQueue.php
Browse files Browse the repository at this point in the history
PlanetScale provides great serverless MySQL-compatible database and guide on how to integrate it in Laravel (https://planetscale.com/docs/tutorials/connect-laravel-app) but under hood uses Vitess.

However it looks that Vitess doesn't support "skip" queries:
```SQLSTATE[HY000]: General error: 1105 syntax error at position 185 near 'SKIP' (SQL: select * from `jobs` where `queue` = default and ((`reserved_at` is null and `available_at` <= 1662479913) or (`reserved_at` <= 1662479823)) order by `id` asc limit 1 FOR UPDATE SKIP LOCKED)```

Following laravel#31536 I've improved engine/version parsing for Vitess so it wouldn't use locks for popping:
```>>> DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME)
=> "mysql"

>>> DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION)
=> "8.0.23-vitess"```
  • Loading branch information
Rihards Ščeredins authored Sep 6, 2022
1 parent 43622bd commit f3533ea
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Queue/DatabaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ protected function getLockForPopping()
if (Str::of($databaseVersion)->contains('MariaDB')) {
$databaseEngine = 'mariadb';
$databaseVersion = Str::before(Str::after($databaseVersion, '5.5.5-'), '-');
} else if (Str::of($databaseVersion)->contains('vitess')) {
$databaseEngine = 'vitess';
$databaseVersion = Str::before($databaseVersion, '-');
}

if (($databaseEngine === 'mysql' && version_compare($databaseVersion, '8.0.1', '>=')) ||
Expand Down

0 comments on commit f3533ea

Please sign in to comment.