| @@ -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'; | 
| @@ -42,8 +42,8 @@ discard block | ||
| 42 | 42 |          foreach ($this->signals as $sig) { | 
| 43 | 43 | $this->pcntl->signal( | 
| 44 | 44 | $sig, | 
| 45 | -                function ($sig)  { | |
| 46 | -                    $this->log->info('received signal. signo: ' . $sig); | |
| 45 | +                function($sig) { | |
| 46 | +                    $this->log->info('received signal. signo: '.$sig); | |
| 47 | 47 |                      $this->log->info('--> sending a signal " to children.'); | 
| 48 | 48 | $this->container->sendSignalToMaster($sig); | 
| 49 | 49 |                      $this->log->info('<-- signal handling has been completed successfully.'); | 
| @@ -53,7 +53,7 @@ discard block | ||
| 53 | 53 | ); | 
| 54 | 54 | } | 
| 55 | 55 | |
| 56 | -        $this->log->info('parent pid: ' . $this->config->get('ownerPid')); | |
| 56 | +        $this->log->info('parent pid: '.$this->config->get('ownerPid')); | |
| 57 | 57 | } | 
| 58 | 58 | |
| 59 | 59 | /** | 
| @@ -77,7 +77,7 @@ discard block | ||
| 77 | 77 | throw $e; | 
| 78 | 78 | } | 
| 79 | 79 | |
| 80 | -        $this->log->info('queued task #' . $this->container->queuedCount()); | |
| 80 | +        $this->log->info('queued task #'.$this->container->queuedCount()); | |
| 81 | 81 | } | 
| 82 | 82 | |
| 83 | 83 | /** | 
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 | */ | 
| 98 | 98 | public function results() | 
| 99 | 99 |      { | 
| 100 | -        foreach($this->container->results() as $r) { | |
| 100 | +        foreach ($this->container->results() as $r) { | |
| 101 | 101 | yield $r; | 
| 102 | 102 | } | 
| 103 | 103 | } | 
| @@ -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 | */ | 
| @@ -119,7 +119,7 @@ discard block | ||
| 119 | 119 |          try { | 
| 120 | 120 | $this->master = $this->pcntl->fork(); | 
| 121 | 121 |          } catch (\RuntimeException $e) { | 
| 122 | - $message = 'failed to fork master: ' . $e->getMessage(); | |
| 122 | + $message = 'failed to fork master: '.$e->getMessage(); | |
| 123 | 123 | $this->log->error($message); | 
| 124 | 124 | throw new \RuntimeException($message); | 
| 125 | 125 | } | 
| @@ -128,8 +128,8 @@ discard block | ||
| 128 | 128 | |
| 129 | 129 |          if (getmypid() === $this->config->get('ownerPid')) { | 
| 130 | 130 | // owner | 
| 131 | -            $this->log->info('pid: ' . getmypid()); | |
| 132 | -            $this->resultQueue  = $this->factory->create('result'); | |
| 131 | +            $this->log->info('pid: '.getmypid()); | |
| 132 | +            $this->resultQueue = $this->factory->create('result'); | |
| 133 | 133 | |
| 134 | 134 | return $this->master; | 
| 135 | 135 |          } else { | 
| @@ -137,17 +137,17 @@ discard block | ||
| 137 | 137 | // covered by SnidelTest via master process | 
| 138 | 138 | // master | 
| 139 | 139 | $activeWorkerSet = new ActiveWorkerSet(); | 
| 140 | -            $this->log->info('pid: ' . $this->master->getPid()); | |
| 140 | +            $this->log->info('pid: '.$this->master->getPid()); | |
| 141 | 141 | |
| 142 | 142 |              foreach ($this->signals as $sig) { | 
| 143 | -                $this->pcntl->signal($sig, function ($sig) use ($activeWorkerSet) { | |
| 143 | +                $this->pcntl->signal($sig, function($sig) use ($activeWorkerSet) { | |
| 144 | 144 | $this->receivedSignal = $sig; | 
| 145 | -                    $this->log->info('received signal: ' . $sig); | |
| 145 | +                    $this->log->info('received signal: '.$sig); | |
| 146 | 146 | |
| 147 | 147 |                      if ($activeWorkerSet->count() === 0) { | 
| 148 | 148 |                          $this->log->info('no worker is active.'); | 
| 149 | 149 |                      } else { | 
| 150 | -                        $this->log->info('------> sending signal to workers. signal: ' . $sig); | |
| 150 | +                        $this->log->info('------> sending signal to workers. signal: '.$sig); | |
| 151 | 151 | $activeWorkerSet->terminate($sig); | 
| 152 | 152 |                          $this->log->info('<------ sent signal'); | 
| 153 | 153 | } | 
| @@ -155,7 +155,7 @@ discard block | ||
| 155 | 155 | }); | 
| 156 | 156 | } | 
| 157 | 157 | |
| 158 | -            $concurrency = (int)$this->config->get('concurrency'); | |
| 158 | +            $concurrency = (int) $this->config->get('concurrency'); | |
| 159 | 159 |              for ($i = 0; $i < $concurrency; $i++) { | 
| 160 | 160 | $activeWorkerSet->add($this->forkWorker()); | 
| 161 | 161 | } | 
| @@ -185,7 +185,7 @@ discard block | ||
| 185 | 185 |          try { | 
| 186 | 186 | $process = $this->pcntl->fork(); | 
| 187 | 187 |          } catch (\RuntimeException $e) { | 
| 188 | - $message = 'failed to fork worker: ' . $e->getMessage(); | |
| 188 | + $message = 'failed to fork worker: '.$e->getMessage(); | |
| 189 | 189 | $this->log->error($message); | 
| 190 | 190 | throw new \RuntimeException($message); | 
| 191 | 191 | } | 
| @@ -194,22 +194,22 @@ discard block | ||
| 194 | 194 | |
| 195 | 195 |          if (getmypid() === $this->master->getPid()) { | 
| 196 | 196 | // master | 
| 197 | -            $this->log->info('forked worker. pid: ' . $worker->getPid()); | |
| 197 | +            $this->log->info('forked worker. pid: '.$worker->getPid()); | |
| 198 | 198 | return $worker; | 
| 199 | 199 |          } else { | 
| 200 | 200 | // @codeCoverageIgnoreStart | 
| 201 | 201 | // covered by SnidelTest via worker process | 
| 202 | 202 | // worker | 
| 203 | -            $this->log->info('has forked. pid: ' . getmypid()); | |
| 203 | +            $this->log->info('has forked. pid: '.getmypid()); | |
| 204 | 204 | |
| 205 | 205 |              foreach ($this->signals as $sig) { | 
| 206 | -                $this->pcntl->signal($sig, function ($sig) { | |
| 206 | +                $this->pcntl->signal($sig, function($sig) { | |
| 207 | 207 | $this->receivedSignal = $sig; | 
| 208 | 208 | exit; | 
| 209 | 209 | }, false); | 
| 210 | 210 | } | 
| 211 | 211 | |
| 212 | -            register_shutdown_function(function () use ($worker) { | |
| 212 | +            register_shutdown_function(function() use ($worker) { | |
| 213 | 213 |                  if ($this->receivedSignal === null && $worker->isInProgress()) { | 
| 214 | 214 | $worker->error(); | 
| 215 | 215 | } | 
| @@ -245,14 +245,14 @@ discard block | ||
| 245 | 245 | */ | 
| 246 | 246 | public function sendSignalToMaster($sig = SIGTERM) | 
| 247 | 247 |      { | 
| 248 | -        $this->log->info('----> sending signal to master. signal: ' . $sig); | |
| 248 | +        $this->log->info('----> sending signal to master. signal: '.$sig); | |
| 249 | 249 | posix_kill($this->master->getPid(), $sig); | 
| 250 | 250 |          $this->log->info('<---- sent signal.'); | 
| 251 | 251 | |
| 252 | 252 |          $this->log->info('----> waiting for master shutdown.'); | 
| 253 | 253 | $status = null; | 
| 254 | 254 | $this->pcntl->waitpid($this->master->getPid(), $status); | 
| 255 | -        $this->log->info('<---- master shutdown. status: ' . $status); | |
| 255 | +        $this->log->info('<---- master shutdown. status: '.$status); | |
| 256 | 256 | $this->master = null; | 
| 257 | 257 | } | 
| 258 | 258 | |
| @@ -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 | } |