ProcessQueue

Class
Final: Yes

Executes queued processes sequentially while supporting detached entries and optional failure suppression.

Description

Regular processes are executed in the order they were added and block the queue until completion. Detached processes are started in the order they were added but do not block subsequent entries.

A detached process that starts successfully is considered dispatched. Because this implementation does not wait for detached processes to finish during run(), their eventual runtime exit status cannot be incorporated into the final queue result. However, a detached process that cannot be started at all is treated as a startup failure and MAY affect the final status code unless its failure is explicitly configured to be ignored.

Buffered detached output is flushed only after the blocking portion of the queue has finished, which keeps later process output from interleaving with currently running blocking commands.

Table of Contents

Interfaces

ProcessQueueInterface

Defines a queue responsible for collecting and executing process instances.

Properties

 : ReflectionProperty|null
$entries

Stores queued process entries in insertion order.

 : array<int, Process, ignoreFailure: bool, detached: bool, label: string}>
$runningDetachedProcesses

Stores detached processes that have already been started and whose output SHALL be emitted only after blocking processes finish.

 : array<int, Process, label: string, standardOutput: string, errorOutput: string}>

Methods

 : mixed
add()

Adds a process to the queue.

 : void
run()

Runs the queued processes and returns the resulting status code.

 : int
wait()

Waits for detached processes to finish and flushes completed buffered output.

 : void
createBufferedOutputCallback()

Creates a callback that buffers detached process output until flushing.

 : callable(string, string): void
createOutputCallback()

Creates a callback that forwards process output to the configured output.

 : callable(string, string): void
flushDetachedProcessesOutput()

Flushes completed detached process output in enqueue order.

 : bool
formatProcessCommandLine()

Formats the configured process command line without shell escaping noise.

 : string
getProcessCommandLine()

Reads the raw configured Process command line.

 : array<int, string>|string
resolveLabel()

Resolves the label used when presenting queued process output.

 : string
runBlockingProcess()

Runs a process synchronously and returns its exit code.

 : int
runLabeledBlockingProcess()

Runs a blocking process inside a grouped GitHub Actions log section.

 : int
startDetachedProcess()

Starts a process in detached mode without waiting for completion.

 : int
writeDetachedOutput()

Writes buffered detached output to the configured output.

 : bool
Properties

$commandLineProperty

Private Static
private static ReflectionProperty|null $commandLineProperty = null

$entries

Private

Stores queued process entries in insertion order.

private array<int, Process, ignoreFailure: bool, detached: bool, label: string}> $entries = []

$runningDetachedProcesses

Private

Stores detached processes that have already been started and whose output SHALL be emitted only after blocking processes finish.

private array<int, Process, label: string, standardOutput: string, errorOutput: string}> $runningDetachedProcesses = []
Methods

add()

Public

Adds a process to the queue.

public add(Process  $process[, bool  $ignoreFailure = false][, bool  $detached = false][, string|null  $label = null]) : void
Parameters
$process : Process

Description

the process instance that SHALL be added to the queue

$ignoreFailure : bool = false

Description

indicates whether a failure of this process MUST NOT affect the final queue result

$detached : bool = false

Description

indicates whether this process SHALL be started without blocking the next queued process

$label : string|null = null

Description

an optional label that MAY be used to present the process output as a grouped block

run()

Public

Runs the queued processes and returns the resulting status code.

public run([OutputInterface  $output = new NullOutput()]) : int

Description

The returned status code represents the first non-zero exit code observed among non-ignored blocking processes, or among non-ignored detached processes that fail to start. Detached processes that start successfully are not awaited iteratively inside run() and therefore do not contribute their eventual runtime exit code to the returned result.

Parameters
$output : OutputInterface = new NullOutput()

Description

the output used during execution

Return values
int

Description

the final exit status code produced by the queue execution

wait()

Public

Waits for detached processes to finish and flushes completed buffered output.

public wait([OutputInterface|null  $output = null]) : void
Parameters
$output : OutputInterface|null = null

Description

the output interface to which process output and diagnostics MAY be written

createBufferedOutputCallback()

Private

Creates a callback that buffers detached process output until flushing.

private createBufferedOutputCallback(Process, label: string, standardOutput: string, errorOutput: string}  $entry) : callable(string, string): void
Parameters
$entry : Process, label: string, standardOutput: string, errorOutput: string}
Return values
callable(string, string): void

createOutputCallback()

Private

Creates a callback that forwards process output to the configured output.

private createOutputCallback(OutputInterface  $output) : callable(string, string): void

Description

The callback SHALL stream both standard output and error output exactly as received, preserving ANSI escape sequences when the underlying command emits them.

Parameters
$output : OutputInterface

Description

the output destination

Return values
callable(string, string): void

flushDetachedProcessesOutput()

Private

Flushes completed detached process output in enqueue order.

private flushDetachedProcessesOutput(OutputInterface  $output) : bool
Parameters
$output : OutputInterface

Description

the output that SHALL receive detached process output

Return values
bool

Description

whether at least one detached process output has been flushed

formatProcessCommandLine()

Private

Formats the configured process command line without shell escaping noise.

private formatProcessCommandLine(Process  $process) : string
Parameters
$process : Process

Description

the queued process instance

Return values
string

Description

the human-readable command line

getProcessCommandLine()

Private

Reads the raw configured Process command line.

private getProcessCommandLine(Process  $process) : array<int, string>|string

Description

Symfony keeps the configured command line in a private property, so the queue reads it reflectively to build a cleaner default label than the shell-escaped output returned by Process::getCommandLine().

Parameters
$process : Process

Description

the queued process instance

Return values
array<int, string>|string

resolveLabel()

Private

Resolves the label used when presenting queued process output.

private resolveLabel(Process  $process[, string|null  $label = null]) : string
Parameters
$process : Process

Description

the queued process instance

$label : string|null = null

Description

the optional label provided by the caller

Return values
string

Description

the resolved presentation label

runBlockingProcess()

Private

Runs a process synchronously and returns its exit code.

private runBlockingProcess(Process  $process, OutputInterface  $output) : int
Parameters
$process : Process

Description

the process to execute

$output : OutputInterface

Description

the output that SHALL receive process output

Return values
int

Description

The exit code returned by the process. A startup failure is normalized to a non-zero exit code.

runLabeledBlockingProcess()

Private

Runs a blocking process inside a grouped GitHub Actions log section.

private runLabeledBlockingProcess(Process  $process, OutputInterface  $output, string  $label) : int
Parameters
$process : Process

Description

the process to execute

$output : OutputInterface

Description

the output that SHALL receive process output

$label : string

Description

the label that SHALL be used to group command output

Return values
int

Description

the resulting process exit code

startDetachedProcess()

Private

Starts a process in detached mode without waiting for completion.

private startDetachedProcess(Process  $process, string  $label) : int

Description

A detached process is considered successfully dispatched when its startup sequence completes without throwing an exception.

Parameters
$process : Process

Description

the process to start

$label : string

Description

the label used when presenting the buffered output

Return values
int

Description

returns 0 when the process starts successfully, or a non-zero value when startup fails

writeDetachedOutput()

Private

Writes buffered detached output to the configured output.

private writeDetachedOutput( string  $standardOutput, string  $errorOutput, OutputInterface  $output) : bool
Parameters
$standardOutput : string
$errorOutput : string
$output : OutputInterface

Description

the output that SHALL receive detached process output

Return values
bool

Description

always returns true to support grouped callback usage