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

aJob

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

class

aJob

aJob.php:37

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).

abstract class MMO\core\jobs\aJob implements MMO\core\interfaces\iLogEmitter use MMO\core\classes\tLogEmitter
Espace de noms
MMO\core\jobs
Implémente
iLogEmitter
Utilise les traits
tLogEmitter
A job only implements [`run`](https://mmoframework.fr/fr/documentation/mmo.core/php/jobs/aJob.md#ajob-run). While it works, it says where it is: - its logs (`$this->info(...)`, and every log dispatched in its process, a library's warning included) become `log` events; - [`progress`](https://mmoframework.fr/fr/documentation/mmo.core/php/jobs/aJob.md#ajob-progress): how far it is (`progress` events, and the record's `progress`); - [`html`](https://mmoframework.fr/fr/documentation/mmo.core/php/jobs/aJob.md#ajob-html): a fragment to show as is (a report, a table); - what [`run`](https://mmoframework.fr/fr/documentation/mmo.core/php/jobs/aJob.md#ajob-run) returns is its `result`. It calls [`shouldStop`](https://mmoframework.fr/fr/documentation/mmo.core/php/jobs/aJob.md#ajob-shouldstop) in its loops, and returns early when it is true: it then ends `stopped`. An exception it throws ends it `failed`, with the exception as its `error`. public function run(array $params): mixed { $ids = Products::Ids(); foreach ($ids as $i => $id) { if ($this->shouldStop()) {break;} Products::Reindex($id); $this->progress($i + 1, count($ids), $id); } return ['reindexed' => $i + 1]; } } $id = JobStore::Shared()->start(ReindexJob::class);
class ReindexJob extends aJob { static public function Title(): string {return 'Reindex the products';}

Index

heartbeatInterval
id
lastHeartbeat
lastProgress
otherVerbosity
progress
progressInterval
progressSent
stopped
store
verbosity
alert($message, $context)Action must be taken immediately.
backtraces($message, $context)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).
critical($message, $context)Critical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask.
debug($message, $context)Detailed debug information.
debugName()
emergency($message, $context)System is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.
emit($type, $data)Add an event of any type to the job's events (JobStore::emit).
error($message, $context)Runtime errors that do not require immediate action but should typically be logged and monitored.
Exclusive() static
flushProgress($record)Send the last progress if progress skipped it (what the job ends with).
getId()
getStore()
getVerbosity()
heartbeat($changes, $force)Refresh the record's heartbeat (with $changes), at most every $heartbeatInterval seconds.
html($html)Show an html fragment as is (a report, a table): the people following the job see it in its log.
info($message, $context)Interesting events. No-op if INFO is currently filtered out by the verbosity mask.
isStopped()
log($level, $message, $context)Logs with an arbitrary level.
notice($message, $context)Normal but significant events.
progress($done, $total, $label)Say how far the job is.
requestStop()Ask the job to stop from inside its own process (what JobRunner does on SIGTERM).
run($params) abstractDo the work.
setVerbosity($verb)Set the current verbosity mask, replacing whatever it was before.
shouldStop()Whether the job was asked to stop (JobStore::stop, or SIGTERM): call it in loops, and return when true.
testVerbosity($level)Test whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.
Title() static
warning($message, $context)Exceptional occurrences that are not errors.
__construct($store, $id)

Propriétés11

heartbeatInterval

protected int $heartbeatInterval = 5
Type
int

id

protected string $id
Type
string

lastHeartbeat

protected int $lastHeartbeat = 0
Type
int

lastProgress

protected float $lastProgress = 0.0
Type
float

otherVerbosity

int $otherVerbosity = 31
Type
int

progress

protected ?array $progress = null
Type
null | array

progressInterval

protected float $progressInterval = 0.5
Type
float

progressSent

protected bool $progressSent = true
Type
bool

stopped

protected bool $stopped = false
Type
bool

store

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

verbosity

#[MMO\core\attributes\Serialize(order: -1000)] protected int $verbosity = 31
Type
int

Méthodes28

alert($message, $context)

tLogEmitter.php:121

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.
$messageStringable | string
$context = []array
retournevoid
$this->alert('payment gateway unreachable for 5 minutes.');

backtraces($message, $context)

tLogEmitter.php:234

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
$message = ' -- TRACES -- 'string
$context = []array
retournevoid
$this->backtraces('unexpected state reached in {method}.', ['method' => __METHOD__]);

critical($message, $context)

tLogEmitter.php:138

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.
$messageStringable | string
$context = []array
retournevoid
$this->critical('unexpected {exception}.', ['exception' => $e]);

debug($message, $context)

tLogEmitter.php:219

Detailed debug information. No-op if DEBUG is currently filtered out by the verbosity mask.

function debug(Stringable|string $message, array $context = []): void
$messageStringable | string
$context = []array
retournevoid
$this->debug('set stream [{stream}].', ['stream' => $stream]);

debugName()

aJob.php:100
function debugName(): string
retournestringthe job's title and id, as its logs' origin

emergency($message, $context)

tLogEmitter.php:103

System is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.

function emergency(Stringable|string $message, array $context = []): void
$messageStringable | string
$context = []array
retournevoid
$this->emergency('database connection lost.');

error($message, $context)

tLogEmitter.php:154

Runtime 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.
$messageStringable | string
$context = []array
retournevoid
$this->error('failed to write [{file}].', ['file' => $filename]);

Exclusive()

staticaJob.php:85
static function Exclusive(): bool
retourneboolwhether only one job of this class may run at a time (JobStore::create refuses a second)

flushProgress($record)

aJob.php:157

Send the last progress if progress skipped it (what the job ends with).

function flushProgress(bool $record = true): ?array
$record = trueboolalso write it in the record now (else with the next heartbeat)
retournenull | arraythe last progress given

getStore()

aJob.php:95
function getStore(): MMO\core\jobs\JobStore
retourneJobStorethe store the job is recorded in

getVerbosity()

tLogEmitter.php:38
function getVerbosity(): int
retourneintthe current verbosity, as a bitmask of iLogLevel::* constants
$this->getVerbosity() === (iLogLevel::ERROR_PLUS); // true if only errors/critical/alert/emergency are enabled

heartbeat($changes, $force)

aJob.php:189

Refresh the record's heartbeat (with $changes), at most every $heartbeatInterval seconds.

protected function heartbeat(array $changes = [], bool $force = false): void
$changes = []array
$force = falseboolwrite now whatever the interval
retournevoid

html($html)

aJob.php:170

Show an html fragment as is (a report, a table): the people following the job see it in its log.

function html(string $html): void
$htmlstring
retournevoid

info($message, $context)

tLogEmitter.php:204

Interesting 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.
$messageStringable | string
$context = []array
retournevoid
$this->info('routing [{request}] ...', ['request' => $request]);

log($level, $message, $context)

tLogEmitter.php:81

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.
$level
$messageStringable | string
$context = []arrayignored if $message is a Log
retournevoid
$this->log(self::ERROR, 'disk usage at {percent}%.', ['percent' => 92]); $this->log('error', $caughtException); //string levels are resolved through \MMO\core\debug\flags()

notice($message, $context)

tLogEmitter.php:187

Normal but significant events. No-op if NOTICE is currently filtered out by the verbosity mask.

function notice(Stringable|string $message, array $context = []): void
$messageStringable | string
$context = []array
retournevoid
$this->notice('-- START -- ({mode}): {time}', ['mode' => MMO_MODE, 'time' => date('r')]);

progress($done, $total, $label)

aJob.php:136

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.
$doneint | float
$total = nullint | float | nullnull when unknown
$label = nullnull | stringwhat it is doing now
retournevoid
$this->progress($i + 1, count($rows), "row $i");

requestStop()

aJob.php:124

Ask the job to stop from inside its own process (what JobRunner does on SIGTERM).

function requestStop(): void
retournevoid

run($params)

abstractaJob.php:77

Do the work.

abstract function run(array $params): mixed
$paramsarraythe parameters it was started with (JobStore::create)
retournemixedits result: anything json can encode, kept in the record's result

setVerbosity($verb)

tLogEmitter.php:64

Set the current verbosity mask, replacing whatever it was before.

function setVerbosity(string|int|null $verb = null): void
$verb = nullstring | int | nulla bitmask of iLogLevel::* constants, or a level name/expression resolved through \MMO\core\debug\flags() (e.g. 'error+' for iLogLevel::ERROR_PLUS)
retournevoid
$this->setVerbosity(iLogLevel::WARNING_PLUS); // only log warnings and above $this->setVerbosity('all'); // log everything

shouldStop()

aJob.php:109

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.
retournebool

testVerbosity($level)

tLogEmitter.php:50

Test whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.

function testVerbosity(string|int $level): int
$levelstring | inta iLogLevel::* constant/bitmask, or a level name resolved through \MMO\core\debug\flags()
retourneintthe 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

Title()

staticaJob.php:80
static function Title(): string
retournestringwhat the job does, for the people following it

warning($message, $context)

tLogEmitter.php:172

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.
$messageStringable | string
$context = []array
retournevoid
$this->warning('{count} logs were dropped.', ['count' => 3]);

__construct($store, $id)

aJob.php:68
function __construct(MMO\core\jobs\JobStore $store, string $id)
$storeJobStore
$idstringthe job's id in $store
Membres hérités (19)
ConstantesDéclaré parDescription
ALERTiLogLevelAlert: Action must be taken immediately.
ALLiLogLevelMask for all
ALL_PLUSiLogLeveldebug everything
BACKTRACEiLogLevel
CRITICALiLogLevelCritical: Critical conditions.
DEBUGiLogLevelDebug: Detailed debug information.
DEEPiLogLeveldebug everything with arguments
EMERGENCYiLogLevelEmergency: System is unusable.
ERRORiLogLevelError: Runtime errors that do not require immediate action but should typically be logged and monitored.
ERROR_PLUSiLogLevelMask for all error
FATALiLogLevelMask for all fatal error
INFOiLogLevelInfo: Interesting events.
INFO_PLUSiLogLevelMask for all errors/warning/notices/info
MEMORYiLogLevelinclude backtrace object
NOTICEiLogLevelNotice: Normal but significant events.
NOTICE_PLUSiLogLevelMask for all errors/warning/notices/info
TRACEiLogLevelinclude backtrace as origins
WARNINGiLogLevelWarning: Exceptional occurrences that are not errors.
WARNING_PLUSiLogLevelMask for all errors and warnings