JobStore
MMO\core\jobs · 1 symbol · generated 27 Oct 2026
JobStore
JobStore.php:32Where long jobs (aJob) live: one folder per job, that the job's own process writes and any number of readers (a page, an SSE stream, the command line) read -- the job never talks to a browser.
- Namespace
MMO\core\jobs- Extends
- aModule
Index
| DONE | ||
| FAILED | ||
| ID_PATTERN | an id: its creation date, then random hex (sorting ids sorts jobs by date) | |
| QUEUED | ||
| RUNNING | ||
| STOPPED | ||
| bootstrap | ||
| folder | ||
| keepDays | ||
| php | ||
| startTimeout | ||
| create($class, $params, $info) | Record a new job, without starting it (start does both). | |
| delete($id) | Delete a job's folder (not while it runs). | |
| emit($id, $event) | Append an event to a job's events (events.ndjson); t (microtime) is added when missing. | |
| events($id, $offset, $max) | A job's events after a position: only whole lines, so a line still being written is read next time. | |
| exists($id) | ||
| get($id) | A job, as recorded (JobStore), with its state checked against its process: a queued or running job whose process is gone (killed, crashed before its shutdown handler) is recorded failed. | |
| getBootstrap() | ||
| getFolder() | ||
| getPhp() | ||
| isLost($job) | ||
| isStopRequested($id) | ||
| kill($id) | Kill a job's process right away (SIGKILL), when asking it to stop (stop) is not enough: it gets no chance to clean up, and ends stopped. | |
| list($class, $limit) | Every job, newest first (get). | |
| path($id, $file) | ||
| prune($days) | Delete the finished jobs older than $keepDays. | |
| read($id) | ||
| running($class) | ||
| spawn($id) | Run a recorded job in its own process, detached from this one (setsid, so it outlives a web request and its php-fpm worker), with no time limit. | |
| start($class, $params, $info) | Record a job and run it in its own detached process (create, spawn). | |
| stop($id) | Ask a job to stop: it does at its next aJob::shouldStop check, and ends stopped. | |
| update($id, $changes) | Change a job's record, under a lock (the job's process and its readers both write it). | |
| write($id, $job) | Write a job's record whole, atomically (a reader never sees half of it). |
Constants6
DONE
FAILED
ID_PATTERN
an id: its creation date, then random hex (sorting ids sorts jobs by date)
QUEUED
RUNNING
STOPPED
Properties5
bootstrap
folder
keepDays
- Type
- int
php
startTimeout
- Type
- int
Methods22
create($class, $params, $info)
JobStore.php:110Record a new job, without starting it (start does both).
| $class | string | |
| $params = [] | array | what aJob::run receives |
| $info = [] | array | anything the caller wants kept with it (who started it, from where) |
| returns | string | the job's id |
| throws | if $class is not an aJob. | |
| throws | if $class is exclusive (aJob::Exclusive) and one of its jobs is already running. |
delete($id)
JobStore.php:279Delete a job's folder (not while it runs).
emit($id, $event)
JobStore.php:311Append an event to a job's events (events.ndjson); t (microtime) is added when missing.
| $id | string | |
| $event | array | |
| returns | int | the event's position (the byte offset of its end: what a reader passes back to events) |
events($id, $offset, $max)
JobStore.php:337A job's events after a position: only whole lines, so a line still being written is read next time.
| $id | string | |
| $offset = 0 | int | where the last read stopped (0: from the start) |
| $max = 1048576 | int | the most bytes to read at once |
| returns | array | array<array>, offset: int} each event with its id (its position), and where to read next |
exists($id)
JobStore.php:79get($id)
JobStore.php:197A job, as recorded (JobStore), with its state checked against its process: a queued or running job whose process is gone (killed, crashed before its shutdown handler) is recorded failed.
getBootstrap()
JobStore.php:94| returns | string | the file the launcher requires before running a job ($bootstrap). |
getFolder()
JobStore.php:60| returns | string | the folder holding every job (created if needed). |
getPhp()
JobStore.php:87isLost($job)
JobStore.php:413isStopRequested($id)
JobStore.php:258kill($id)
JobStore.php:269Kill a job's process right away (SIGKILL), when asking it to stop (stop) is not enough: it gets no chance to clean up, and ends stopped.
list($class, $limit)
JobStore.php:218Every job, newest first (get).
path($id, $file)
JobStore.php:73| $id | string | |
| $file = '' | string | a file of the job's folder, '' for the folder itself |
| returns | string | |
| throws | if $id is not a job id (it is used in a path). |
prune($days)
JobStore.php:290Delete the finished jobs older than $keepDays.
read($id)
JobStore.php:373running($class)
JobStore.php:231spawn($id)
JobStore.php:161Run a recorded job in its own process, detached from this one (setsid, so it outlives a web request and its php-fpm worker), with no time limit. It writes a launcher (run.php) that sets the application up (getBootstrap) and hands over to JobRunner::Main.
start($class, $params, $info)
JobStore.php:147Record a job and run it in its own detached process (create, spawn).
stop($id)
JobStore.php:244Ask a job to stop: it does at its next aJob::shouldStop check, and ends stopped. A queued job that has not started yet is stopped at once.
update($id, $changes)
JobStore.php:388Change a job's record, under a lock (the job's process and its readers both write it).
write($id, $job)
JobStore.php:405Write a job's record whole, atomically (a reader never sees half of it).
Inherited members (48)
| Constants | Declared by | Description | |
|---|---|---|---|
ALERT | iLogLevel | Alert: Action must be taken immediately. | |
ALL | iLogLevel | Mask for all | |
ALL_PLUS | iLogLevel | debug everything | |
BACKTRACE | iLogLevel | ||
CRITICAL | iLogLevel | Critical: Critical conditions. | |
DEBUG | iLogLevel | Debug: Detailed debug information. | |
DEEP | iLogLevel | debug everything with arguments | |
EMERGENCY | iLogLevel | Emergency: System is unusable. | |
ERROR | iLogLevel | Error: Runtime errors that do not require immediate action but should typically be logged and monitored. | |
ERROR_PLUS | iLogLevel | Mask for all error | |
FATAL | iLogLevel | Mask for all fatal error | |
INFO | iLogLevel | Info: Interesting events. | |
INFO_PLUS | iLogLevel | Mask for all errors/warning/notices/info | |
MEMORY | iLogLevel | include backtrace object | |
NOTICE | iLogLevel | Notice: Normal but significant events. | |
NOTICE_PLUS | iLogLevel | Mask for all errors/warning/notices/info | |
TRACE | iLogLevel | include backtrace as origins | |
WARNING | iLogLevel | Warning: Exceptional occurrences that are not errors. | |
WARNING_PLUS | iLogLevel | Mask for all errors and warnings |
| Properties | Declared by | Description | |
|---|---|---|---|
verbosity | aModule |
| Methods | Declared by | Description | |
|---|---|---|---|
alert($message, $context) | aModule | Action must be taken immediately. | |
backtraces($message, $context) | aModule | Force-log a message at INFO level together with a full stack trace/memory snapshot (iLogLevel::BACKTRACE), bypassing the verbosity mask entirely (any non-zero verbosity is enough to trigger it). | |
Configure($config) | aModule | Merge $config into this module's configuration in the shared Configuration. | |
critical($message, $context) | aModule | Critical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask. | |
debug($message, $context) | aModule | Detailed debug information. | |
debugName() | aModule | Human-readable identifier used as the default {origin} in this instance's log messages. | |
DefaultConfig() | aModule | The config a module starts from before anything loaded via Configuration is merged in. | |
emergency($message, $context) | aModule | System is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask. | |
error($message, $context) | aModule | Runtime errors that do not require immediate action but should typically be logged and monitored. | |
getVerbosity() | aModule | ||
info($message, $context) | aModule | Interesting events. No-op if INFO is currently filtered out by the verbosity mask. | |
Instantiate($config) | aModule | (Re)create the shared instance immediately, configured with $config merged into the class's existing config. | |
IsShared() | aModule | ||
log($level, $message, $context) | aModule | Logs with an arbitrary level. | |
notice($message, $context) | aModule | Normal but significant events. | |
offsetExists($key) | aModule | \ArrayAccess::offsetExists -- tells whether $key is a declared property at all, regardless of whether it is currently readable/writable through array access. | |
offsetGet($key) | aModule | \ArrayAccess::offsetGet -- reads a property directly, unless it has a #[Serialize(serialize: 'methodName')] attribute, in which case that zero-argument method is called instead (e.g. | |
offsetSet($key, $value) | aModule | \ArrayAccess::offsetSet -- sets a property directly, unless it has a #[Serialize(unserialize: 'methodName')] attribute, in which case that method is called with $value instead (e.g. | |
offsetUnset($key) | aModule | \ArrayAccess::offsetUnset -- equivalent to $module[$key] = null. | |
serialize($path, $serializer) | aModule | \MMO\core\interfaces\iSerializable::serialize -- exports every property (via | |
setVerbosity($verb) | aModule | Set the current verbosity mask, replacing whatever it was before. | |
Shared() | aModule | Get the shared instance, creating (and configuring) it on first call. | |
testVerbosity($level) | aModule | Test whether a given level (or set of levels) is currently enabled by this instance's verbosity mask. | |
traitUnshare($serialize) | aModule | Remove the shared instance, so the next Shared() call creates a fresh one. | |
unserialize($data, $path, $instances) | aModule | \MMO\core\interfaces\iSerializable::unserialize -- merges $data onto DefaultConfig, runs it through the (possibly overridden) constructor, then applies each resulting value to its property (via | |
Unshare($serialize) | aModule | Like tSingleton::Unshare, but also disconnects this module's instance from every event it was listening to (via Event::DisconnectListeners) before dropping it. | |
warning($message, $context) | aModule | Exceptional occurrences that are not errors. | |
__construct($config) | aModule | protected constructor, so it is not possible to do new Module(...) called by the serialization process just before being injected with data. |