Memory
extends AbstractTaskAdapter
in package
In-memory adapter class
A hermetic, single-process reference implementation of the adapter contract. Used to prove the contract in tests independent of any real storage backend, and as a fake for consumers of this package to test against.
Tags
Table of Contents
Constants
- TASK_CLAIM_TTL = 90
- How long, in seconds, a claim blocks a *same-window* re-claim.
Properties
- $dead : array<string|int, mixed>
- Dead-letter jobs, keyed by job ID
- $jobs : array<string|int, mixed>
- Jobs, keyed by job ID
- $leaseSeconds : int
- Reservation lease length, in seconds
- $meta : array<string|int, mixed>
- Job metadata (sequence, status, availableAt, reservedUntil), keyed by job ID
- $priority : string
- Queue priority
- $sequence : int
- Push/reserve ordering sequence counter
- $taskClaims : array<string|int, mixed>
- Task claim state: taskId => [window, expiresAt]
- $tasks : array<string|int, mixed>
- Scheduled tasks, keyed by task ID
Methods
- __construct() : mixed
- Constructor
- bury() : AdapterInterface
- Move a job to the dead-letter store (terminal)
- claimTaskRun() : bool
- Atomically claim a task's current due-window
- clear() : AdapterInterface
- Clear pending and reserved jobs (not dead-letter jobs)
- clearDead() : Memory
- clearTasks() : AbstractTaskAdapter
- Clear all scheduled task
- count() : int
- Count of pending + reserved jobs
- countDead() : int
- delete() : AdapterInterface
- Permanently remove a job (success/ack)
- deleteDeadJob() : Memory
- getAllTasks() : array<string|int, mixed>
- Get every scheduled task, keyed by task ID.
- getDeadJob() : mixed
- getDeadJobs() : array<string|int, mixed>
- getPriority() : string
- getTask() : Task|null
- Get scheduled task
- getTaskCount() : int
- Get scheduled tasks count
- getTasks() : array<string|int, mixed>
- Get scheduled tasks
- hasDeadJobs() : bool
- hasJobs() : bool
- Whether there are pending or reserved jobs
- hasTasks() : bool
- Has scheduled tasks
- isFifo() : bool
- isFilo() : bool
- isLifo() : bool
- isLilo() : bool
- push() : AdapterInterface
- Push a job onto the queue
- release() : AdapterInterface
- Put a reserved job back to pending. $delay overrides the job's own backoff schedule when given; otherwise release() computes the delay from $job->getBackoffDelay().
- removeTask() : AbstractTaskAdapter
- Remove scheduled task
- reserve() : AbstractJob|null
- Atomically claim the next eligible job and lease it. Returns null if nothing is eligible (no pending jobs due, or all reserved jobs have a live lease).
- retryDeadJob() : AdapterInterface
- Move a dead-letter job back to pending
- schedule() : AbstractTaskAdapter
- Schedule job with queue
- setPriority() : AbstractAdapter
- updateTask() : AbstractTaskAdapter
- Update scheduled task
Constants
TASK_CLAIM_TTL
How long, in seconds, a claim blocks a *same-window* re-claim.
protected
mixed
TASK_CLAIM_TTL
= 90
Shared by every concrete adapter's claimTaskRun() implementation. Not configurable - it has no relationship to any task's cron recurrence interval (the explicit window value each implementation compares against is what makes that safe). It does need to outlast the longest window a claim must survive: a claim is never refreshed or released while its task runs, and a coarse (non-sub-minute) task is due across its entire ~60-second window (evaluate() stays true for the whole minute, not just at :00), so a second worker can legitimately re-evaluate the same coarse task's window many seconds after the first worker claimed it. 90 seconds covers a full 60-second coarse window plus slack, not just one claim-then-execute round trip.
Properties
$dead
Dead-letter jobs, keyed by job ID
protected
array<string|int, mixed>
$dead
= []
$jobs
Jobs, keyed by job ID
protected
array<string|int, mixed>
$jobs
= []
$leaseSeconds
Reservation lease length, in seconds
protected
int
$leaseSeconds
= 60
$meta
Job metadata (sequence, status, availableAt, reservedUntil), keyed by job ID
protected
array<string|int, mixed>
$meta
= []
$priority
Queue priority
protected
string
$priority
= 'FIFO'
$sequence
Push/reserve ordering sequence counter
protected
int
$sequence
= 0
$taskClaims
Task claim state: taskId => [window, expiresAt]
protected
array<string|int, mixed>
$taskClaims
= []
$tasks
Scheduled tasks, keyed by task ID
protected
array<string|int, mixed>
$tasks
= []
Methods
__construct()
Constructor
public
__construct([int $leaseSeconds = 60 ][, string|null $priority = null ]) : mixed
Parameters
- $leaseSeconds : int = 60
- $priority : string|null = null
bury()
Move a job to the dead-letter store (terminal)
public
bury(AbstractJob $job[, string|null $reason = null ]) : AdapterInterface
Parameters
- $job : AbstractJob
- $reason : string|null = null
Return values
AdapterInterfaceclaimTaskRun()
Atomically claim a task's current due-window
public
claimTaskRun(string $taskId, string $window) : bool
Parameters
- $taskId : string
- $window : string
Return values
boolclear()
Clear pending and reserved jobs (not dead-letter jobs)
public
clear() : AdapterInterface
Return values
AdapterInterfaceclearDead()
public
clearDead() : Memory
Return values
MemoryclearTasks()
Clear all scheduled task
public
clearTasks() : AbstractTaskAdapter
Return values
AbstractTaskAdaptercount()
Count of pending + reserved jobs
public
count() : int
Return values
intcountDead()
public
countDead() : int
Return values
intdelete()
Permanently remove a job (success/ack)
public
delete(AbstractJob $job) : AdapterInterface
Parameters
- $job : AbstractJob
Return values
AdapterInterfacedeleteDeadJob()
public
deleteDeadJob(string $jobId) : Memory
Parameters
- $jobId : string
Return values
MemorygetAllTasks()
Get every scheduled task, keyed by task ID.
public
getAllTasks() : array<string|int, mixed>
Concrete, not abstract, so an adapter only overrides it if its storage can genuinely do better than one fetch per task - which the Database and Redis adapters both can, and do. This fallback is the loop it replaces, kept so that adding the method to TaskAdapterInterface doesn't oblige every adapter to reimplement it.
Return values
array<string|int, mixed> —taskId => Task
getDeadJob()
public
getDeadJob(string $jobId[, bool $unserialize = true ]) : mixed
Parameters
- $jobId : string
- $unserialize : bool = true
getDeadJobs()
public
getDeadJobs([bool $unserialize = true ]) : array<string|int, mixed>
Parameters
- $unserialize : bool = true
Return values
array<string|int, mixed>getPriority()
public
getPriority() : string
Return values
stringgetTask()
Get scheduled task
public
getTask(string $taskId) : Task|null
Parameters
- $taskId : string
Return values
Task|nullgetTaskCount()
Get scheduled tasks count
public
getTaskCount() : int
Return values
intgetTasks()
Get scheduled tasks
public
getTasks() : array<string|int, mixed>
Return values
array<string|int, mixed>hasDeadJobs()
public
hasDeadJobs() : bool
Return values
boolhasJobs()
Whether there are pending or reserved jobs
public
hasJobs() : bool
Return values
boolhasTasks()
Has scheduled tasks
public
hasTasks() : bool
Return values
boolisFifo()
public
isFifo() : bool
Return values
boolisFilo()
public
isFilo() : bool
Return values
boolisLifo()
public
isLifo() : bool
Return values
boolisLilo()
public
isLilo() : bool
Return values
boolpush()
Push a job onto the queue
public
push(AbstractJob $job) : AdapterInterface
Parameters
- $job : AbstractJob
Return values
AdapterInterfacerelease()
Put a reserved job back to pending. $delay overrides the job's own backoff schedule when given; otherwise release() computes the delay from $job->getBackoffDelay().
public
release(AbstractJob $job[, int|null $delay = null ]) : AdapterInterface
Parameters
- $job : AbstractJob
- $delay : int|null = null
Return values
AdapterInterfaceremoveTask()
Remove scheduled task
public
removeTask(string $taskId) : AbstractTaskAdapter
Parameters
- $taskId : string
Return values
AbstractTaskAdapterreserve()
Atomically claim the next eligible job and lease it. Returns null if nothing is eligible (no pending jobs due, or all reserved jobs have a live lease).
public
reserve() : AbstractJob|null
Return values
AbstractJob|nullretryDeadJob()
Move a dead-letter job back to pending
public
retryDeadJob(string $jobId) : AdapterInterface
Parameters
- $jobId : string
Return values
AdapterInterfaceschedule()
Schedule job with queue
public
schedule(Task $task) : AbstractTaskAdapter
Parameters
- $task : Task
Return values
AbstractTaskAdaptersetPriority()
public
setPriority([string $priority = 'FIFO' ]) : AbstractAdapter
Parameters
- $priority : string = 'FIFO'
Return values
AbstractAdapterupdateTask()
Update scheduled task
public
updateTask(Task $task) : AbstractTaskAdapter
Parameters
- $task : Task