MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

JobRunner

MMO\core\jobs · 1 symbole · générée le 27 Oct 2026

class

JobRunner

JobRunner.php:28

Runs one recorded job (JobStore) in the current process, from start to end, and records how it went: its state, its logs as events, its result or its error. It is what a job's own process does (the launcher

class MMO\core\jobs\JobRunner
Espace de noms
MMO\core\jobs
Voir
JobStore::spawn writes calls Main); execute also runs a job in the current process (a test, a command that wants to wait for it).
While the job runs: - no time limit, and a browser leaving does not stop it; - an exclusive job ([`aJob::Exclusive`](https://mmoframework.fr/fr/documentation/mmo.core/php/jobs/aJob.md#ajob-exclusive)) holds a lock on its class: a second one fails at once; - every log dispatched in the process (the job's and the libraries' it uses) becomes a `log` event; - SIGTERM/SIGINT ask it to stop ([`aJob::shouldStop`](https://mmoframework.fr/fr/documentation/mmo.core/php/jobs/aJob.md#ajob-shouldstop)) instead of killing it; - a fatal error still ends it `failed`, with the error.
//in a job's own process (what run.php does) exit(JobRunner::Main($id)); //in this process, waiting for the end $state = (new JobRunner(JobStore::Shared(), $id))->execute(); // 'done'

Index

finished
id
job
listener
lock
store
Error($e) static
execute()Run the job and record its end.
finish($state, $result, $error)Record the job's end, once, and release what it held.
listen()Turn the logs dispatched while the job runs into log events (before the application's own logger): the job's own, and the others from aJob::$otherVerbosity up (a library's info, a query, wou…
lock($job)Hold the exclusive lock of the job's class (aJob::Exclusive): JobStore::create already refuses a second job of an exclusive class, but two could have been created at the same time.
Main($id, $folder) staticA job process's entry point (JobStore::spawn's launcher).
shutdown()Record a fatal error's end (the job's process dies without reaching the end of execute).
trapSignals($job)SIGTERM/SIGINT ask the job to stop rather than kill it (once it has noticed, another one kills it).
__construct($store, $id)

Propriétés6

finished

protected bool $finished = false
Type
bool

id

protected string $id
Type
string

job

protected ?MMO\core\jobs\aJob $job = null
Type
null | aJob

listener

protected $listener = null

lock

protected $lock = null

store

protected MMO\core\jobs\JobStore $store
Type
JobStore

Méthodes9

Error($e)

staticJobRunner.php:107
static function Error(Throwable $e): array
$eThrowable
retournearraystring, class: string, file: string, line: int, trace: string} an error, as recorded

execute()

JobRunner.php:63

Run the job and record its end.

function execute(): string
retournestringits final state: done, stopped or failed

finish($state, $result, $error)

JobRunner.php:118

Record the job's end, once, and release what it held.

protected function finish(string $state, mixed $result, ?array $error): void
$statestring
$resultmixed
$errornull | array
retournevoid

listen()

JobRunner.php:161

Turn the logs dispatched while the job runs into log events (before the application's own logger): the job's own, and the others from aJob::$otherVerbosity up (a library's info, a query, would drown the job's).

protected function listen(): void
retournevoid

lock($job)

JobRunner.php:143

Hold the exclusive lock of the job's class (aJob::Exclusive): JobStore::create already refuses a second job of an exclusive class, but two could have been created at the same time.

protected function lock(MMO\core\jobs\aJob $job): void
$jobaJob
retournevoid
lèveif another job of the class holds it.

Main($id, $folder)

staticJobRunner.php:51

A job process's entry point (JobStore::spawn's launcher).

static function Main(string $id, ?string $folder = null): int
$idstring
$folder = nullnull | stringthe store's folder, when it is not the configured one
retourneintthe process's exit code: 0 when the job ended done or stopped

shutdown()

JobRunner.php:96

Record a fatal error's end (the job's process dies without reaching the end of execute).

function shutdown(): void
retournevoid

trapSignals($job)

JobRunner.php:177

SIGTERM/SIGINT ask the job to stop rather than kill it (once it has noticed, another one kills it).

protected function trapSignals(MMO\core\jobs\aJob $job): void
$jobaJob
retournevoid

__construct($store, $id)

JobRunner.php:43
function __construct(MMO\core\jobs\JobStore $store, string $id)
$storeJobStore
$idstringthe job to run, recorded queued in $store