Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow real time interaction with output of executing processes #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class ProcessManager
/**
* @param Process[] $processes
* @param int $maxParallel
* @param int $poll
* @param int $poll microseconds
* @param Callable $callback takes 3 args: $type, $buffer, $process
*/
public function runParallel(array $processes, $maxParallel, $poll = 1000)
public function runParallel(array $processes, $maxParallel, $poll = 1000, $callback = null))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser error )) at the end

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @gimler, thanks for your work. Your goal here is to "modify the command based on the previous finished". It looks like you are trying to accomplish a sequential process execution. This simple wrapper was meant for parallel processing. Let me know if there is something that I am missing from my understanding.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually i have 4 phantomjs instances and n testcases. Each phantom has his own port and should only execute one test a time.
So i must manipulate the command before when i know which phantom instance is free.

Actually i have three events before after and processing.

{
$this->validateProcesses($processes);

Expand All @@ -29,7 +30,11 @@ public function runParallel(array $processes, $maxParallel, $poll = 1000)

// start the initial stack of processes
foreach ($currentProcesses as $process) {
$process->start();
$process->start(function ($type, $buffer) use ($callback, $process) {
if ($callback) {
$callback($type, $buffer, $process);
}
});
}

do {
Expand All @@ -44,7 +49,11 @@ public function runParallel(array $processes, $maxParallel, $poll = 1000)
// directly add and start new process after the previous finished
if (count($processesQueue) > 0) {
$nextProcess = array_shift($processesQueue);
$nextProcess->start();
$nextProcess->start(function ($type, $buffer) use ($callback, $nextProcess) {
if ($callback) {
$callback($type, $buffer, $nextProcess);
}
});
$currentProcesses[] = $nextProcess;
}
}
Expand Down