@@ -42,7 +42,7 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | private function context() |
| 44 | 44 | { |
| 45 | - $pid = getmypid(); |
|
| 45 | + $pid = getmypid(); |
|
| 46 | 46 | switch ($pid) { |
| 47 | 47 | case $this->ownerPid: |
| 48 | 48 | $role = 'owner'; |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | $this->params['id'] = spl_object_hash($this); |
| 24 | 24 | if (!$this->params['driver']) { |
| 25 | 25 | $this->params['driver'] = new FlatFileDriver( |
| 26 | - sys_get_temp_dir() . DIRECTORY_SEPARATOR . $this->params['id'] |
|
| 26 | + sys_get_temp_dir().DIRECTORY_SEPARATOR.$this->params['id'] |
|
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | private $resultQueue; |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | - * @param int $ownerPid |
|
| 60 | + * @param \Ackintosh\Snidel\Log $log |
|
| 61 | 61 | */ |
| 62 | 62 | public function __construct(Config $config, $log) |
| 63 | 63 | { |
@@ -77,6 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * @param \Ackintosh\Snidel\Task |
| 80 | + * @param \Ackintosh\Snidel\Task\Task $task |
|
| 80 | 81 | * @return void |
| 81 | 82 | * @throws \RuntimeException |
| 82 | 83 | */ |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | try { |
| 116 | 116 | $this->master = $this->pcntl->fork(); |
| 117 | 117 | } catch (\RuntimeException $e) { |
| 118 | - $message = 'failed to fork master: ' . $e->getMessage(); |
|
| 118 | + $message = 'failed to fork master: '.$e->getMessage(); |
|
| 119 | 119 | $this->log->error($message); |
| 120 | 120 | throw new \RuntimeException($message); |
| 121 | 121 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | if (getmypid() === $this->config->get('ownerPid')) { |
| 126 | 126 | // owner |
| 127 | - $this->log->info('pid: ' . getmypid()); |
|
| 128 | - $this->resultQueue = $this->factory->create('result'); |
|
| 127 | + $this->log->info('pid: '.getmypid()); |
|
| 128 | + $this->resultQueue = $this->factory->create('result'); |
|
| 129 | 129 | |
| 130 | 130 | return $this->master; |
| 131 | 131 | } else { |
@@ -133,17 +133,17 @@ discard block |
||
| 133 | 133 | // covered by SnidelTest via master process |
| 134 | 134 | // master |
| 135 | 135 | $workerPool = new WorkerPool(); |
| 136 | - $this->log->info('pid: ' . $this->master->getPid()); |
|
| 136 | + $this->log->info('pid: '.$this->master->getPid()); |
|
| 137 | 137 | |
| 138 | 138 | foreach ($this->signals as $sig) { |
| 139 | - $this->pcntl->signal($sig, function ($sig) use ($workerPool) { |
|
| 139 | + $this->pcntl->signal($sig, function($sig) use ($workerPool) { |
|
| 140 | 140 | $this->receivedSignal = $sig; |
| 141 | - $this->log->info('received signal: ' . $sig); |
|
| 141 | + $this->log->info('received signal: '.$sig); |
|
| 142 | 142 | |
| 143 | 143 | if ($workerPool->count() === 0) { |
| 144 | 144 | $this->log->info('no worker is active.'); |
| 145 | 145 | } else { |
| 146 | - $this->log->info('------> sending signal to workers. signal: ' . $sig); |
|
| 146 | + $this->log->info('------> sending signal to workers. signal: '.$sig); |
|
| 147 | 147 | $workerPool->terminate($sig); |
| 148 | 148 | $this->log->info('<------ sent signal'); |
| 149 | 149 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | }); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $concurrency = (int)$this->config->get('concurrency'); |
|
| 154 | + $concurrency = (int) $this->config->get('concurrency'); |
|
| 155 | 155 | for ($i = 0; $i < $concurrency; $i++) { |
| 156 | 156 | $workerPool->add($this->forkWorker()); |
| 157 | 157 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | try { |
| 182 | 182 | $process = $this->pcntl->fork(); |
| 183 | 183 | } catch (\RuntimeException $e) { |
| 184 | - $message = 'failed to fork worker: ' . $e->getMessage(); |
|
| 184 | + $message = 'failed to fork worker: '.$e->getMessage(); |
|
| 185 | 185 | $this->log->error($message); |
| 186 | 186 | throw new \RuntimeException($message); |
| 187 | 187 | } |
@@ -190,22 +190,22 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | if (getmypid() === $this->master->getPid()) { |
| 192 | 192 | // master |
| 193 | - $this->log->info('forked worker. pid: ' . $worker->getPid()); |
|
| 193 | + $this->log->info('forked worker. pid: '.$worker->getPid()); |
|
| 194 | 194 | return $worker; |
| 195 | 195 | } else { |
| 196 | 196 | // @codeCoverageIgnoreStart |
| 197 | 197 | // covered by SnidelTest via worker process |
| 198 | 198 | // worker |
| 199 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
| 199 | + $this->log->info('has forked. pid: '.getmypid()); |
|
| 200 | 200 | |
| 201 | 201 | foreach ($this->signals as $sig) { |
| 202 | - $this->pcntl->signal($sig, function ($sig) { |
|
| 202 | + $this->pcntl->signal($sig, function($sig) { |
|
| 203 | 203 | $this->receivedSignal = $sig; |
| 204 | 204 | exit; |
| 205 | 205 | }, false); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - register_shutdown_function(function () use ($worker) { |
|
| 208 | + register_shutdown_function(function() use ($worker) { |
|
| 209 | 209 | if ($this->receivedSignal === null && $worker->isInProgress()) { |
| 210 | 210 | $worker->error(); |
| 211 | 211 | } |
@@ -241,14 +241,14 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | public function sendSignalToMaster($sig = SIGTERM) |
| 243 | 243 | { |
| 244 | - $this->log->info('----> sending signal to master. signal: ' . $sig); |
|
| 244 | + $this->log->info('----> sending signal to master. signal: '.$sig); |
|
| 245 | 245 | posix_kill($this->master->getPid(), $sig); |
| 246 | 246 | $this->log->info('<---- sent signal.'); |
| 247 | 247 | |
| 248 | 248 | $this->log->info('----> waiting for master shutdown.'); |
| 249 | 249 | $status = null; |
| 250 | 250 | $this->pcntl->waitpid($this->master->getPid(), $status); |
| 251 | - $this->log->info('<---- master shutdown. status: ' . $status); |
|
| 251 | + $this->log->info('<---- master shutdown. status: '.$status); |
|
| 252 | 252 | $this->master = null; |
| 253 | 253 | } |
| 254 | 254 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $this->coordinator = new Coordinator($this->config, $this->log); |
| 38 | 38 | $this->coordinator->forkMaster(); |
| 39 | 39 | $this->registerSignalHandler($this->coordinator, $this->log); |
| 40 | - $this->log->info('parent pid: ' . $this->config->get('ownerPid')); |
|
| 40 | + $this->log->info('parent pid: '.$this->config->get('ownerPid')); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | try { |
| 55 | 55 | $this->coordinator->enqueue(new Task($callable, $args, $tag)); |
| 56 | 56 | } catch (\RuntimeException $e) { |
| 57 | - $this->log->error('failed to enqueue the task: ' . $e->getMessage()); |
|
| 57 | + $this->log->error('failed to enqueue the task: '.$e->getMessage()); |
|
| 58 | 58 | throw $e; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $this->log->info('queued task #' . $this->coordinator->queuedCount()); |
|
| 61 | + $this->log->info('queued task #'.$this->coordinator->queuedCount()); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function results() |
| 80 | 80 | { |
| 81 | - foreach($this->coordinator->results() as $r) { |
|
| 81 | + foreach ($this->coordinator->results() as $r) { |
|
| 82 | 82 | yield $r; |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | foreach ($this->signals as $sig) { |
| 110 | 110 | $pcntl->signal( |
| 111 | 111 | $sig, |
| 112 | - function ($sig) use ($log, $coordinator) { |
|
| 113 | - $log->info('received signal. signo: ' . $sig); |
|
| 112 | + function($sig) use ($log, $coordinator) { |
|
| 113 | + $log->info('received signal. signo: '.$sig); |
|
| 114 | 114 | $log->info('--> sending a signal " to children.'); |
| 115 | 115 | $coordinator->sendSignalToMaster($sig); |
| 116 | 116 | $log->info('<-- signal handling has been completed successfully.'); |