Commaaa2
This commit is contained in:
@@ -2,14 +2,16 @@
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Queue\ClearableQueue;
|
||||
use Illuminate\Contracts\Queue\Queue as QueueContract;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Queue\Jobs\DatabaseJob;
|
||||
use Illuminate\Queue\Jobs\DatabaseJobRecord;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use PDO;
|
||||
|
||||
class DatabaseQueue extends Queue implements QueueContract
|
||||
class DatabaseQueue extends Queue implements QueueContract, ClearableQueue
|
||||
{
|
||||
/**
|
||||
* The database connection instance.
|
||||
@@ -46,14 +48,20 @@ class DatabaseQueue extends Queue implements QueueContract
|
||||
* @param string $table
|
||||
* @param string $default
|
||||
* @param int $retryAfter
|
||||
* @param bool $dispatchAfterCommit
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Connection $database, $table, $default = 'default', $retryAfter = 60)
|
||||
public function __construct(Connection $database,
|
||||
$table,
|
||||
$default = 'default',
|
||||
$retryAfter = 60,
|
||||
$dispatchAfterCommit = false)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->default = $default;
|
||||
$this->database = $database;
|
||||
$this->retryAfter = $retryAfter;
|
||||
$this->dispatchAfterCommit = $dispatchAfterCommit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,9 +87,15 @@ class DatabaseQueue extends Queue implements QueueContract
|
||||
*/
|
||||
public function push($job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->pushToDatabase($queue, $this->createPayload(
|
||||
$job, $this->getQueue($queue), $data
|
||||
));
|
||||
return $this->enqueueUsing(
|
||||
$job,
|
||||
$this->createPayload($job, $this->getQueue($queue), $data),
|
||||
$queue,
|
||||
null,
|
||||
function ($payload, $queue) {
|
||||
return $this->pushToDatabase($queue, $payload);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,9 +122,15 @@ class DatabaseQueue extends Queue implements QueueContract
|
||||
*/
|
||||
public function later($delay, $job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->pushToDatabase($queue, $this->createPayload(
|
||||
$job, $this->getQueue($queue), $data
|
||||
), $delay);
|
||||
return $this->enqueueUsing(
|
||||
$job,
|
||||
$this->createPayload($job, $this->getQueue($queue), $data),
|
||||
$queue,
|
||||
$delay,
|
||||
function ($payload, $queue, $delay) {
|
||||
return $this->pushToDatabase($queue, $payload, $delay);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,10 +252,16 @@ class DatabaseQueue extends Queue implements QueueContract
|
||||
protected function getLockForPopping()
|
||||
{
|
||||
$databaseEngine = $this->database->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
$databaseVersion = $this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
$databaseVersion = $this->database->getConfig('version') ?? $this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
|
||||
if ($databaseEngine == 'mysql' && ! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=') ||
|
||||
$databaseEngine == 'pgsql' && version_compare($databaseVersion, '9.5', '>=')) {
|
||||
if (Str::of($databaseVersion)->contains('MariaDB')) {
|
||||
$databaseEngine = 'mariadb';
|
||||
$databaseVersion = Str::before(Str::after($databaseVersion, '5.5.5-'), '-');
|
||||
}
|
||||
|
||||
if (($databaseEngine === 'mysql' && version_compare($databaseVersion, '8.0.1', '>=')) ||
|
||||
($databaseEngine === 'mariadb' && version_compare($databaseVersion, '10.6.0', '>=')) ||
|
||||
($databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>='))) {
|
||||
return 'FOR UPDATE SKIP LOCKED';
|
||||
}
|
||||
|
||||
@@ -321,6 +347,38 @@ class DatabaseQueue extends Queue implements QueueContract
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a reserved job from the reserved queue and release it.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\Jobs\DatabaseJob $job
|
||||
* @param int $delay
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAndRelease($queue, $job, $delay)
|
||||
{
|
||||
$this->database->transaction(function () use ($queue, $job, $delay) {
|
||||
if ($this->database->table($this->table)->lockForUpdate()->find($job->getJobId())) {
|
||||
$this->database->table($this->table)->where('id', $job->getJobId())->delete();
|
||||
}
|
||||
|
||||
$this->release($queue, $job->getJobRecord(), $delay);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all of the jobs from the queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @return int
|
||||
*/
|
||||
public function clear($queue)
|
||||
{
|
||||
return $this->database->table($this->table)
|
||||
->where('queue', $this->getQueue($queue))
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue or return the default.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user