FileQueue
in package
implements
IQueue
File-based queue implementation.
Stores jobs in JSON files on the filesystem. Simple and requires no database, but not suitable for high-throughput applications.
Table of Contents
Interfaces
- IQueue
- Queue interface for managing job queues.
Properties
- $_failedPath : string
- $_path : string
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
- ensureDirectoryExists() : void
- Ensure directory exists
- getJobFilename() : string
- Get job filename
- getJobFilenameById() : string
- Get job filename by ID
- getQueuePath() : string
- Get queue directory path
- serializeJob() : string
- Serialize job to JSON
Properties
$_failedPath
private
string
$_failedPath
$_path
private
string
$_path
Methods
__construct()
public
__construct([array<string|int, mixed> $config = [] ]) : mixed
Parameters
- $config : array<string|int, mixed> = []
-
Configuration array
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
ensureDirectoryExists()
Ensure directory exists
private
ensureDirectoryExists(string $path) : void
Parameters
- $path : string
getJobFilename()
Get job filename
private
getJobFilename(QueuedJob $job) : string
Parameters
- $job : QueuedJob
Return values
stringgetJobFilenameById()
Get job filename by ID
private
getJobFilenameById(string $id, string $queue) : string
Parameters
- $id : string
- $queue : string
Return values
stringgetQueuePath()
Get queue directory path
private
getQueuePath(string $queue) : string
Parameters
- $queue : string
Return values
stringserializeJob()
Serialize job to JSON
private
serializeJob(QueuedJob $job) : string
Parameters
- $job : QueuedJob