JobQueue
in package
File-based job queue implementation
Table of Contents
Constants
- PRIORITY_HIGH = 'high'
- PRIORITY_LOW = 'low'
- PRIORITY_NORMAL = 'normal'
Properties
- $lockFile : string
- $queuePath : string
Methods
- __construct() : mixed
- JobQueue constructor
- complete() : void
- Mark a job as completed
- fail() : void
- Mark a job as failed
- getStatistics() : array<string|int, mixed>
- Get queue statistics
- isEmpty() : bool
- Check if queue is empty
- pop() : Job|null
- Pop the next job from the queue
- popWithId() : array<string|int, mixed>|null
- Pop a job from the queue with its queue ID
- push() : string
- Push a job to the queue
- pushDelayed() : string
- Push a job for delayed execution
- size() : int
- Get queue size
- calculateRetryTime() : string
- Calculate retry time with exponential backoff
- cleanupCompleted() : void
- Clean up old completed items
- countCompletedToday() : int
- Count completed jobs today
- deleteQueueItem() : void
- Delete queue item
- generateQueueId() : string
- Generate a unique queue ID
- getItemsInDirectory() : array<string|int, mixed>
- Get items in a specific directory
- getPendingItems() : array<string|int, mixed>
- Get all pending items
- getQueueItem() : array<string|int, mixed>|null
- Read queue item from disk
- initializeDirectories() : void
- Initialize queue directories
- lock() : bool
- Acquire lock for queue operations
- moveQueueItem() : void
- Move queue item between directories
- reconstructJob() : Job|null
- Reconstruct a job from queue item
- unlock() : void
- Release queue lock
- writeQueueItem() : void
- Write queue item to disk
Constants
PRIORITY_HIGH
public
array<string|int, mixed>
PRIORITY_HIGH
= 'high'
Priority levels
PRIORITY_LOW
public
mixed
PRIORITY_LOW
= 'low'
PRIORITY_NORMAL
public
mixed
PRIORITY_NORMAL
= 'normal'
Properties
$lockFile
protected
string
$lockFile
$queuePath
protected
string
$queuePath
Methods
__construct()
JobQueue constructor
public
__construct(string $queuePath) : mixed
Parameters
- $queuePath : string
complete()
Mark a job as completed
public
complete(string $queueId) : void
Parameters
- $queueId : string
fail()
Mark a job as failed
public
fail(string $queueId[, string $error = '' ]) : void
Parameters
- $queueId : string
- $error : string = ''
getStatistics()
Get queue statistics
public
getStatistics() : array<string|int, mixed>
Return values
array<string|int, mixed>isEmpty()
Check if queue is empty
public
isEmpty() : bool
Return values
boolpop()
Pop the next job from the queue
public
pop() : Job|null
Return values
Job|nullpopWithId()
Pop a job from the queue with its queue ID
public
popWithId() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —Array with 'job' and 'id' keys
push()
Push a job to the queue
public
push(Job $job[, string $priority = self::PRIORITY_NORMAL ]) : string
Parameters
- $job : Job
- $priority : string = self::PRIORITY_NORMAL
Return values
string —Job queue ID
pushDelayed()
Push a job for delayed execution
public
pushDelayed(Job $job, DateTime $scheduledFor[, string $priority = self::PRIORITY_NORMAL ]) : string
Parameters
- $job : Job
- $scheduledFor : DateTime
- $priority : string = self::PRIORITY_NORMAL
Return values
stringsize()
Get queue size
public
size() : int
Return values
intcalculateRetryTime()
Calculate retry time with exponential backoff
protected
calculateRetryTime(int $attempts) : string
Parameters
- $attempts : int
Return values
stringcleanupCompleted()
Clean up old completed items
protected
cleanupCompleted() : void
countCompletedToday()
Count completed jobs today
protected
countCompletedToday() : int
Return values
intdeleteQueueItem()
Delete queue item
protected
deleteQueueItem(string $queueId, string $directory) : void
Parameters
- $queueId : string
- $directory : string
generateQueueId()
Generate a unique queue ID
protected
generateQueueId(Job $job) : string
Parameters
- $job : Job
Return values
stringgetItemsInDirectory()
Get items in a specific directory
protected
getItemsInDirectory(string $directory) : array<string|int, mixed>
Parameters
- $directory : string
Return values
array<string|int, mixed>getPendingItems()
Get all pending items
protected
getPendingItems() : array<string|int, mixed>
Return values
array<string|int, mixed>getQueueItem()
Read queue item from disk
protected
getQueueItem(string $queueId, string $directory) : array<string|int, mixed>|null
Parameters
- $queueId : string
- $directory : string
Return values
array<string|int, mixed>|nullinitializeDirectories()
Initialize queue directories
protected
initializeDirectories() : void
lock()
Acquire lock for queue operations
protected
lock() : bool
Return values
boolmoveQueueItem()
Move queue item between directories
protected
moveQueueItem(string $queueId, string $fromDir, string $toDir) : void
Parameters
- $queueId : string
- $fromDir : string
- $toDir : string
reconstructJob()
Reconstruct a job from queue item
protected
reconstructJob(array<string|int, mixed> $item) : Job|null
Parameters
- $item : array<string|int, mixed>
Return values
Job|nullunlock()
Release queue lock
protected
unlock() : void
writeQueueItem()
Write queue item to disk
protected
writeQueueItem(array<string|int, mixed> $item, string $directory) : void
Parameters
- $item : array<string|int, mixed>
- $directory : string