1 | <?php |
||
24 | class ParallelExecutor implements ExecutorInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var InputInterface |
||
28 | */ |
||
29 | private $input; |
||
30 | |||
31 | /** |
||
32 | * @var OutputInterface |
||
33 | */ |
||
34 | private $output; |
||
35 | |||
36 | /** |
||
37 | * @var Informer |
||
38 | */ |
||
39 | private $informer; |
||
40 | |||
41 | /** |
||
42 | * @var Application |
||
43 | */ |
||
44 | private $console; |
||
45 | |||
46 | /** |
||
47 | * @param InputInterface $input |
||
48 | * @param OutputInterface $output |
||
49 | * @param Informer $informer |
||
50 | * @param Application $console |
||
51 | */ |
||
52 | 1 | public function __construct(InputInterface $input, OutputInterface $output, Informer $informer, Application $console) |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 1 | public function run($tasks, $hosts) |
|
117 | |||
118 | /** |
||
119 | * Run task on hosts. |
||
120 | * |
||
121 | * @param Host[] $hosts |
||
122 | * @param Task $task |
||
123 | * @return int |
||
124 | */ |
||
125 | 1 | private function runTask(array $hosts, Task $task) |
|
149 | |||
150 | /** |
||
151 | * Get process for task on host. |
||
152 | * |
||
153 | * @param Host $host |
||
154 | * @param Task $task |
||
155 | * @return Process |
||
156 | */ |
||
157 | 1 | protected function getProcess($host, Task $task) |
|
181 | |||
182 | /** |
||
183 | * Start all of the processes. |
||
184 | * |
||
185 | * @param Process[] $processes |
||
186 | * @return void |
||
187 | */ |
||
188 | 1 | protected function startProcesses(array $processes) |
|
194 | |||
195 | /** |
||
196 | * Determine if any of the processes are running. |
||
197 | * |
||
198 | * @param Process[] $processes |
||
199 | * @return bool |
||
200 | */ |
||
201 | 1 | protected function areRunning(array $processes) |
|
210 | |||
211 | /** |
||
212 | * Gather the output from all of the processes. |
||
213 | * |
||
214 | * @param Process[] $processes |
||
215 | * @param callable $callback |
||
216 | */ |
||
217 | 1 | protected function gatherOutput(array $processes, callable $callback) |
|
232 | |||
233 | /** |
||
234 | * Gather the cumulative exit code for the processes. |
||
235 | * |
||
236 | * @param Process[] $processes |
||
237 | * @return int |
||
238 | */ |
||
239 | 1 | protected function gatherExitCodes(array $processes) |
|
249 | |||
250 | /** |
||
251 | * Generate options and arguments string. |
||
252 | * @return string |
||
253 | */ |
||
254 | 1 | private function generateOptions() |
|
255 | { |
||
256 | 1 | $verbosity = new VerbosityString($this->output); |
|
257 | 1 | $input = $verbosity; |
|
258 | |||
259 | // Get user arguments |
||
260 | 1 | foreach ($this->console->getUserDefinition()->getArguments() as $argument) { |
|
261 | $value = $this->input->getArgument($argument->getName()); |
||
262 | if ($value) { |
||
263 | $input .= " $value"; |
||
264 | } |
||
265 | } |
||
266 | |||
267 | // Get user options |
||
268 | 1 | foreach ($this->console->getUserDefinition()->getOptions() as $option) { |
|
269 | $name = $option->getName(); |
||
270 | $value = $this->input->getOption($name); |
||
271 | |||
272 | if ($value) { |
||
273 | $input .= " --{$name}"; |
||
274 | |||
275 | if ($option->acceptValue()) { |
||
276 | $input .= " {$value}"; |
||
277 | } |
||
278 | } |
||
279 | } |
||
280 | |||
281 | 1 | return $input; |
|
282 | } |
||
283 | |||
284 | 1 | private function generateArguments(): string |
|
295 | } |
||
296 |