Database
extends AbstractRegistry
in package
Database registry class
One row per worker: the ID as primary key, last_seen_at as its own column so the table is directly queryable by an operator, and the full record as JSON.
prune() is inherited as a read-filter-delete loop rather than overridden with a bulk DELETE: pop-db's string where() parser is only reliable for simple expressions and this codebase has no precedent for a string '<' comparison (src/Adapter/Database.php uses the lessThanOrEqualTo() predicate API wherever it needs one). A registry holds tens of rows, so this costs nothing real.
Tags
Table of Contents
Properties
- $db : AbstractAdapter|null
- Database adapter
- $table : string|null
- Table name
Methods
- __construct() : mixed
- Constructor
- all() : array<string|int, mixed>
- Fetch every stored record, keyed by worker ID
- createTable() : Database
- Create the registry table
- delete() : void
- Remove a record. A no-op if the ID isn't there.
- getDb() : AbstractAdapter|null
- Get the database adapter
- getTable() : string|null
- Get the table name
- prune() : int
- Remove every record whose heartbeat is older than the given number of seconds, plus any stored entry that can no longer be decoded, returning how many were removed in total.
- read() : WorkerRecord|null
- Fetch a record by ID, or null if it isn't there
- write() : void
- Store a record, replacing any existing record with the same ID
- decode() : WorkerRecord|null
- Decode a stored record, or null if the payload is unusable
- encode() : string
- Encode a record for storage
- isExpired() : bool
- Whether a record's heartbeat is older than the given number of seconds. Shared by every backend's prune() so the cutoff rule can't drift between them.
- purgeUndecodable() : int
- Remove stored entries that can no longer be decoded into a WorkerRecord, returning how many were removed.
Properties
$db
Database adapter
protected
AbstractAdapter|null
$db
= null
$table
Table name
protected
string|null
$table
= null
Methods
__construct()
Constructor
public
__construct(AbstractAdapter $db[, string $table = 'pop_worker_registry' ]) : mixed
Parameters
- $db : AbstractAdapter
- $table : string = 'pop_worker_registry'
all()
Fetch every stored record, keyed by worker ID
public
all() : array<string|int, mixed>
Return values
array<string|int, mixed>createTable()
Create the registry table
public
createTable(string $table) : Database
Parameters
- $table : string
Return values
Databasedelete()
Remove a record. A no-op if the ID isn't there.
public
delete(string $id) : void
Parameters
- $id : string
getDb()
Get the database adapter
public
getDb() : AbstractAdapter|null
Return values
AbstractAdapter|nullgetTable()
Get the table name
public
getTable() : string|null
Return values
string|nullprune()
Remove every record whose heartbeat is older than the given number of seconds, plus any stored entry that can no longer be decoded, returning how many were removed in total.
public
prune(int $olderThanSeconds) : int
Concrete here rather than per-backend: the expiry half is expressible purely in terms of all()/delete()/isExpired(), and four byte-identical copies would be four places for the rule to drift.
Parameters
- $olderThanSeconds : int
Return values
intread()
Fetch a record by ID, or null if it isn't there
public
read(string $id) : WorkerRecord|null
Parameters
- $id : string
Return values
WorkerRecord|nullwrite()
Store a record, replacing any existing record with the same ID
public
write(WorkerRecord $record) : void
Parameters
- $record : WorkerRecord
decode()
Decode a stored record, or null if the payload is unusable
protected
decode(string|null $payload) : WorkerRecord|null
Parameters
- $payload : string|null
Return values
WorkerRecord|nullencode()
Encode a record for storage
protected
encode(WorkerRecord $record) : string
JSON, deliberately - registry records are plain scalars and arrays, so this carries none of the unserialize() object-injection surface that job payloads do.
Parameters
- $record : WorkerRecord
Tags
Return values
stringisExpired()
Whether a record's heartbeat is older than the given number of seconds. Shared by every backend's prune() so the cutoff rule can't drift between them.
protected
isExpired(WorkerRecord $record, int $olderThanSeconds) : bool
Parameters
- $record : WorkerRecord
- $olderThanSeconds : int
Return values
boolpurgeUndecodable()
Remove stored entries that can no longer be decoded into a WorkerRecord, returning how many were removed.
protected
purgeUndecodable() : int
These are invisible to all() by design (it skips them so one corrupt entry cannot derail enumeration), which would otherwise make them permanently unreapable - a truncated write or a bad payload would leak for the lifetime of the store. Backends with real storage override this; the default is a no-op for backends that cannot hold an undecodable entry.