Documentation

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
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
3.0.0

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 = []

$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

claimTaskRun()

Atomically claim a task's current due-window

public claimTaskRun(string $taskId, string $window) : bool
Parameters
$taskId : string
$window : string
Return values
bool

count()

Count of pending + reserved jobs

public count() : int
Return values
int

countDead()

public countDead() : int
Return values
int

deleteDeadJob()

public deleteDeadJob(string $jobId) : Memory
Parameters
$jobId : string
Return values
Memory

getAllTasks()

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>

getTask()

Get scheduled task

public getTask(string $taskId) : Task|null
Parameters
$taskId : string
Return values
Task|null

getTaskCount()

Get scheduled tasks count

public getTaskCount() : int
Return values
int

getTasks()

Get scheduled tasks

public getTasks() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasDeadJobs()

public hasDeadJobs() : bool
Return values
bool

hasJobs()

Whether there are pending or reserved jobs

public hasJobs() : bool
Return values
bool

hasTasks()

Has scheduled tasks

public hasTasks() : bool
Return values
bool

release()

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
AdapterInterface

reserve()

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|null

        
On this page

Search results