DatabaseQueue
in package
implements
IQueue
Database-backed queue implementation.
Uses PDO to store jobs in a relational database. Supports SQLite, MySQL, and PostgreSQL.
Table of Contents
Interfaces
- IQueue
- Queue interface for managing job queues.
Properties
- $_connection : PDO
- $_failedJobsTable : string
- $_jobsTable : string
- $_retryAfter : int
Methods
- __construct() : mixed
- clear() : int
- Clear all jobs from the queue
- clearFailedJobs() : int
- Clear all failed jobs
- delete() : void
- Delete a job from the queue Called when a job completes successfully
- failed() : void
- Mark a job as failed Moves the job to failed jobs storage
- forgetFailedJob() : bool
- Delete a failed job
- getFailedJobs() : array<string|int, mixed>
- Get all failed jobs
- pop() : QueuedJob|null
- Pop the next available job from the queue
- push() : string
- Push a job onto the queue
- release() : void
- Release a job back to the queue Used when a job fails and should be retried
- retryFailedJob() : bool
- Retry a failed job
- size() : int
- Get the size of the queue
- createConnection() : PDO
- Create PDO connection from config
- formatException() : string
- Format exception for storage
- releaseExpiredJobs() : void
- Release expired reserved jobs back to the queue
Properties
$_connection
private
PDO
$_connection
$_failedJobsTable
private
string
$_failedJobsTable
= 'failed_jobs'
$_jobsTable
private
string
$_jobsTable
= 'jobs'
$_retryAfter
private
int
$_retryAfter
= 90
Methods
__construct()
public
__construct(array<string|int, mixed> $config) : mixed
Parameters
- $config : array<string|int, mixed>
-
Database configuration
clear()
Clear all jobs from the queue
public
clear([string $queue = 'default' ]) : int
Parameters
- $queue : string = 'default'
-
Queue name (default: 'default')
Tags
Return values
int —Number of jobs cleared
clearFailedJobs()
Clear all failed jobs
public
clearFailedJobs() : int
Tags
Return values
int —Number of failed jobs cleared
delete()
Delete a job from the queue Called when a job completes successfully
public
delete(QueuedJob $job) : void
Parameters
- $job : QueuedJob
-
Job to delete
Tags
failed()
Mark a job as failed Moves the job to failed jobs storage
public
failed(QueuedJob $job, Throwable $exception) : void
Parameters
- $job : QueuedJob
-
Failed job
- $exception : Throwable
-
Exception that caused the failure
Tags
forgetFailedJob()
Delete a failed job
public
forgetFailedJob(string $id) : bool
Parameters
- $id : string
-
Failed job ID
Tags
Return values
bool —True if job was deleted, false if not found
getFailedJobs()
Get all failed jobs
public
getFailedJobs() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of failed job data
pop()
Pop the next available job from the queue
public
pop([string $queue = 'default' ]) : QueuedJob|null
Parameters
- $queue : string = 'default'
-
Queue name (default: 'default')
Tags
Return values
QueuedJob|null —The next job, or null if queue is empty
push()
Push a job onto the queue
public
push(IJob $job[, array<string|int, mixed> $args = [] ][, string $queue = 'default' ][, int $delay = 0 ]) : string
Parameters
- $job : IJob
-
Job instance to queue
- $args : array<string|int, mixed> = []
-
Arguments to pass to the job
- $queue : string = 'default'
-
Queue name (default: 'default')
- $delay : int = 0
-
Delay in seconds before the job is available
Tags
Return values
string —Job ID
release()
Release a job back to the queue Used when a job fails and should be retried
public
release(QueuedJob $job[, int $delay = 0 ]) : void
Parameters
- $job : QueuedJob
-
Job to release
- $delay : int = 0
-
Delay in seconds before job is available again
Tags
retryFailedJob()
Retry a failed job
public
retryFailedJob(string $id) : bool
Parameters
- $id : string
-
Failed job ID
Tags
Return values
bool —True if job was retried, false if not found
size()
Get the size of the queue
public
size([string $queue = 'default' ]) : int
Parameters
- $queue : string = 'default'
-
Queue name (default: 'default')
Tags
Return values
int —Number of jobs in the queue
createConnection()
Create PDO connection from config
private
createConnection(array<string|int, mixed> $config) : PDO
Parameters
- $config : array<string|int, mixed>
Return values
PDOformatException()
Format exception for storage
private
formatException(Throwable $exception) : string
Parameters
- $exception : Throwable
Return values
stringreleaseExpiredJobs()
Release expired reserved jobs back to the queue
private
releaseExpiredJobs(string $queue) : void
Parameters
- $queue : string