A long job: anything too long for a web request (an import, a rebuild, a mass mail), run in its own process with no time limit (JobStore::start), followed live by whoever reads its events (JobStore::events).
Méthodes28
Action must be taken immediately.
function alert(Stringable|string $message, array $context = []): voidExample: Entire website down, database unavailable, etc. This should
trigger the SMS alerts and wake you up.$this->alert('payment gateway unreachable for 5 minutes.');
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).
function backtraces(string $message = ' -- TRACES -- ', array $context = []): void$this->backtraces('unexpected state reached in {method}.', ['method' => __METHOD__]);
Critical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask.
function critical(Stringable|string $message, array $context = []): voidExample : Application component unavailable, unexpected exception.$this->critical('unexpected {exception}.', ['exception' => $e]);
Detailed debug information. No-op if DEBUG is currently filtered out by the verbosity mask.
function debug(Stringable|string $message, array $context = []): void$this->debug('set stream [{stream}].', ['stream' => $stream]);
function debugName(): string| retourne | string | the job's title and id, as its logs' origin |
System is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.
function emergency(Stringable|string $message, array $context = []): void$this->emergency('database connection lost.');
Add an event of any type to the job's events (JobStore::emit).
function emit(string $type, array $data = []): intRuntime errors that do not require immediate action but should typically be logged and monitored.
function error(Stringable|string $message, array $context = []): voidNo-op if ERROR is currently filtered out by the verbosity mask.$this->error('failed to write [{file}].', ['file' => $filename]);
static function Exclusive(): bool| retourne | bool | whether only one job of this class may run at a time (JobStore::create refuses a second) |
Send the last progress if progress skipped it (what the job ends with).
function flushProgress(bool $record = true): ?array| $record = true | bool | also write it in the record now (else with the next heartbeat) |
| retourne | null | array | the last progress given |
function getId(): stringfunction getStore(): MMO\core\jobs\JobStore| retourne | JobStore | the store the job is recorded in |
function getVerbosity(): int| retourne | int | the current verbosity, as a bitmask of iLogLevel::* constants |
$this->getVerbosity() === (iLogLevel::ERROR_PLUS); // true if only errors/critical/alert/emergency are enabled
Refresh the record's heartbeat (with $changes), at most every $heartbeatInterval seconds.
protected function heartbeat(array $changes = [], bool $force = false): void| $changes = [] | array | |
| $force = false | bool | write now whatever the interval |
| retourne | void | |
Show an html fragment as is (a report, a table): the people following the job see it in its log.
function html(string $html): voidInteresting events. No-op if INFO is currently filtered out by the verbosity mask.
function info(Stringable|string $message, array $context = []): voidExample: User logs in, SQL logs.$this->info('routing [{request}] ...', ['request' => $request]);
function isStopped(): bool| retourne | bool | whether the job was asked to stop at some point (shouldStop). |
Logs with an arbitrary level.
function log($level, Stringable|string $message, array $context = []): voidNOTE: $level is filtered against the current [`setVerbosity()`](https://mmoframework.fr/fr/documentation/mmo.core/php/jobs/aJob.md#ajob-setverbosity): if the level is masked out, nothing is
logged/dispatched at all. Return type is `void` (not the dispatched Log) to satisfy \Psr\Log\LoggerInterface.$this->log(self::ERROR, 'disk usage at {percent}%.', ['percent' => 92]);
$this->log('error', $caughtException); //string levels are resolved through \MMO\core\debug\flags()
Normal but significant events. No-op if NOTICE is currently filtered out by the verbosity mask.
function notice(Stringable|string $message, array $context = []): void$this->notice('-- START -- ({mode}): {time}', ['mode' => MMO_MODE, 'time' => date('r')]);
Say how far the job is. Cheap enough to call on every item: events are sent at most every
function progress(int|float $done, int|float|null $total = null, ?string $label = null): void- Voir
$progressInterval seconds, and always for the last item.
$this->progress($i + 1, count($rows), "row $i");
Ask the job to stop from inside its own process (what JobRunner does on SIGTERM).
function requestStop(): voidDo the work.
abstract function run(array $params): mixed| $params | array | the parameters it was started with (JobStore::create) |
| retourne | mixed | its result: anything json can encode, kept in the record's result |
Set the current verbosity mask, replacing whatever it was before.
function setVerbosity(string|int|null $verb = null): void| $verb = null | string | int | null | a bitmask of iLogLevel::* constants, or a level name/expression resolved through \MMO\core\debug\flags() (e.g. 'error+' for iLogLevel::ERROR_PLUS) |
| retourne | void | |
$this->setVerbosity(iLogLevel::WARNING_PLUS); // only log warnings and above
$this->setVerbosity('all'); // log everything
Whether the job was asked to stop (JobStore::stop, or SIGTERM): call it in loops, and return when true.
function shouldStop(): boolAlso keeps the record's heartbeat fresh, so a job that only checks this still shows alive.Test whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.
function testVerbosity(string|int $level): int| $level | string | int | a iLogLevel::* constant/bitmask, or a level name resolved through \MMO\core\debug\flags() |
| retourne | int | the bits of $level that are currently enabled (0 if none of them are) |
$this->testVerbosity(self::DEBUG); // non-zero if debug-level logging is currently enabled
$this->testVerbosity('error'); // same, using the string form
static function Title(): string| retourne | string | what the job does, for the people following it |
Exceptional occurrences that are not errors. No-op if WARNING is currently filtered out by the verbosity mask.
function warning(Stringable|string $message, array $context = []): voidExample: Use of deprecated APIs, poor use of an API, undesirable things
that are not necessarily wrong.$this->warning('{count} logs were dropped.', ['count' => 3]);
function __construct(MMO\core\jobs\JobStore $store, string $id)