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

Match pipes to workers #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
19 changes: 15 additions & 4 deletions lib/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ protected function check_workers() {
}

$pipes = array();
foreach ( $this->workers as $id => $worker ) {
$pipes[ $id ] = $worker->pipes[1];
foreach ( $this->workers as $worker ) {
$pipes[] = $worker->pipes[1];
}

// Grab all the pipes ready to close
Expand All @@ -212,8 +212,18 @@ protected function check_workers() {
$logger = new Logger( $this->db, $this->table_prefix );

// Clean up all of the finished workers
foreach ( $pipes as $id => $stream ) {
$worker = $this->workers[ $id ];
foreach ( $pipes as $stream ) {
// Find which worker it was
$matched = array_filter( $this->workers, function ( $worker ) use ( $stream ) {
return $worker->pipes[1] === $stream;
});
if ( count( $matched ) !== 1 ) {
// This is weird...
printf( '[!!] Could not match pipe to worker!' );
continue;
}

$worker = $matched[0];
if ( ! $worker->is_done() ) {
// Process hasn't exited yet, keep rocking on
continue;
Expand All @@ -227,6 +237,7 @@ protected function check_workers() {
$logger->log_job_completed( $worker->job );
}

$id = array_search( $worker, $this->workers, true );
unset( $this->workers[ $id ] );
}
}
Expand Down