Skip to content
docsv0.3.0

BackgroundJobManagerInterface

Owns the lifecycle of {@see BackgroundJob}s a TUI runtime tracks (e.g. long-running commands surfaced in a job monitor panel). Every mutator here returns the job's new state rather than mutating in place, mirroring {@see BackgroundJob}'s own immutability; implementations MAY additionally publish a {@see \Milpa\Live\ValueObjects\Tui\TuiEvent} through a {@see TuiEventBusInterface} for each transition so a job-monitor node renderer can react without polling.

BackgroundJobManagerInterface::start()

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

Starts and registers a new job in `running` status.

Parameters

Parameters of start()
NameTypeDescription
$labelstring
$commandstring

BackgroundJobManagerInterface::appendOutput()

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

Appends one line of output to an existing job.

Parameters

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

Throws

\RuntimeException If `$jobId` is not a known job.

BackgroundJobManagerInterface::progress()

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

Updates an existing job's progress. Implementations MUST clamp `$progress` to the `[0.0, 1.0]` range.

Parameters

Parameters of progress()
NameTypeDescription
$jobIdstring
$progressfloat

Throws

\RuntimeException If `$jobId` is not a known job.

BackgroundJobManagerInterface::finish()

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

Marks an existing job `done` with the given exit code.

Parameters

Parameters of finish()
NameTypeDescription
$jobIdstring
$exitCodeint

Throws

\RuntimeException If `$jobId` is not a known job.

BackgroundJobManagerInterface::fail()

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

Marks an existing job `failed` with a reason and exit code.

Parameters

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

Throws

\RuntimeException If `$jobId` is not a known job.

BackgroundJobManagerInterface::cancel()

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

Marks an existing job `canceled`.

Parameters

Parameters of cancel()
NameTypeDescription
$jobIdstring

Throws

\RuntimeException If `$jobId` is not a known job.

BackgroundJobManagerInterface::get()

abstract 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

Returns

`null` if `$jobId` is not a known job — unlike the mutators, this lookup does not throw.

BackgroundJobManagerInterface::all()

abstract public function all(): array

All tracked jobs, in registration order.