Skip to content
docsv0.3.0

InMemoryBackgroundJobManager

Tracks long-running work so the interface can show progress. It records job state — it does not spawn processes: the caller runs the work and reports output, progress and outcome back here.

InMemoryBackgroundJobManager::__construct()

public function __construct(?Milpa\Live\Contracts\Tui\TuiEventBusInterface $events = null):

Parameters

Parameters of __construct()
NameTypeDescription
$events?Milpa\Live\Contracts\Tui\TuiEventBusInterface

InMemoryBackgroundJobManager::start()

public function start(string $label, string $command = ''): Milpa\Live\ValueObjects\Tui\BackgroundJob

Records a new running job and returns it.

Parameters

Parameters of start()
NameTypeDescription
$labelstring
$commandstring

InMemoryBackgroundJobManager::appendOutput()

public function appendOutput(string $jobId, string $line, string $stream = 'stdout'): Milpa\Live\ValueObjects\Tui\BackgroundJob

Appends one output line to the job, tagged with the stream it came from.

Parameters

Parameters of appendOutput()
NameTypeDescription
$jobIdstring
$linestring
$streamstring

InMemoryBackgroundJobManager::progress()

public function progress(string $jobId, float $progress): Milpa\Live\ValueObjects\Tui\BackgroundJob

Updates the job's completion fraction, in [0,1].

Parameters

Parameters of progress()
NameTypeDescription
$jobIdstring
$progressfloat

InMemoryBackgroundJobManager::finish()

public function finish(string $jobId, int $exitCode = 0): Milpa\Live\ValueObjects\Tui\BackgroundJob

Marks the job finished with the given exit code.

Parameters

Parameters of finish()
NameTypeDescription
$jobIdstring
$exitCodeint

InMemoryBackgroundJobManager::fail()

public function fail(string $jobId, string $reason, int $exitCode = 1): Milpa\Live\ValueObjects\Tui\BackgroundJob

Marks the job failed, recording why and the exit code.

Parameters

Parameters of fail()
NameTypeDescription
$jobIdstring
$reasonstring
$exitCodeint

InMemoryBackgroundJobManager::cancel()

public function cancel(string $jobId): Milpa\Live\ValueObjects\Tui\BackgroundJob

Marks the job cancelled. It records the outcome — it does not stop the work, which the caller owns.

Parameters

Parameters of cancel()
NameTypeDescription
$jobIdstring

InMemoryBackgroundJobManager::get()

public function get(string $jobId): ?Milpa\Live\ValueObjects\Tui\BackgroundJob

The job with this id, or null when it is unknown.

Parameters

Parameters of get()
NameTypeDescription
$jobIdstring

InMemoryBackgroundJobManager::all()

public function all(): array

Every job this manager has seen, finished ones included.