@@ -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 | */ |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | try { |
126 | 126 | $this->master = $this->pcntl->fork(); |
127 | 127 | } catch (\RuntimeException $e) { |
128 | - $message = 'failed to fork master: ' . $e->getMessage(); |
|
128 | + $message = 'failed to fork master: '.$e->getMessage(); |
|
129 | 129 | $this->log->error($message); |
130 | 130 | throw new \RuntimeException($message); |
131 | 131 | } |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | |
135 | 135 | if (getmypid() === $this->config->get('ownerPid')) { |
136 | 136 | // owner |
137 | - $this->log->info('pid: ' . getmypid()); |
|
138 | - $this->resultQueue = $this->factory->create('result'); |
|
137 | + $this->log->info('pid: '.getmypid()); |
|
138 | + $this->resultQueue = $this->factory->create('result'); |
|
139 | 139 | |
140 | 140 | return $this->master; |
141 | 141 | } else { |
142 | 142 | // master |
143 | 143 | $activeWorkerSet = new ActiveWorkerSet(); |
144 | - $this->log->info('pid: ' . $this->master->getPid()); |
|
144 | + $this->log->info('pid: '.$this->master->getPid()); |
|
145 | 145 | |
146 | 146 | foreach ($this->signals as $sig) { |
147 | - $this->pcntl->signal($sig, function ($sig) use ($activeWorkerSet) { |
|
147 | + $this->pcntl->signal($sig, function($sig) use ($activeWorkerSet) { |
|
148 | 148 | $this->receivedSignal = $sig; |
149 | - $this->log->info('received signal: ' . $sig); |
|
149 | + $this->log->info('received signal: '.$sig); |
|
150 | 150 | |
151 | 151 | if ($activeWorkerSet->count() === 0) { |
152 | 152 | $this->log->info('no worker is active.'); |
153 | 153 | } else { |
154 | - $this->log->info('------> sending signal to workers. signal: ' . $sig); |
|
154 | + $this->log->info('------> sending signal to workers. signal: '.$sig); |
|
155 | 155 | $activeWorkerSet->terminate($sig); |
156 | 156 | $this->log->info('<------ sent signal'); |
157 | 157 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | }); |
160 | 160 | } |
161 | 161 | |
162 | - $concurrency = (int)$this->config->get('concurrency'); |
|
162 | + $concurrency = (int) $this->config->get('concurrency'); |
|
163 | 163 | for ($i = 0; $i < $concurrency; $i++) { |
164 | 164 | $activeWorkerSet->add($this->forkWorker()); |
165 | 165 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | try { |
189 | 189 | $process = $this->pcntl->fork(); |
190 | 190 | } catch (\RuntimeException $e) { |
191 | - $message = 'failed to fork worker: ' . $e->getMessage(); |
|
191 | + $message = 'failed to fork worker: '.$e->getMessage(); |
|
192 | 192 | $this->log->error($message); |
193 | 193 | throw new \RuntimeException($message); |
194 | 194 | } |
@@ -197,21 +197,21 @@ discard block |
||
197 | 197 | |
198 | 198 | if (getmypid() === $this->master->getPid()) { |
199 | 199 | // master |
200 | - $this->log->info('forked worker. pid: ' . $worker->getPid()); |
|
200 | + $this->log->info('forked worker. pid: '.$worker->getPid()); |
|
201 | 201 | return $worker; |
202 | 202 | } else { |
203 | 203 | // worker |
204 | 204 | // @codeCoverageIgnoreStart |
205 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
205 | + $this->log->info('has forked. pid: '.getmypid()); |
|
206 | 206 | |
207 | 207 | foreach ($this->signals as $sig) { |
208 | - $this->pcntl->signal($sig, function ($sig) { |
|
208 | + $this->pcntl->signal($sig, function($sig) { |
|
209 | 209 | $this->receivedSignal = $sig; |
210 | 210 | exit; |
211 | 211 | }, false); |
212 | 212 | } |
213 | 213 | |
214 | - register_shutdown_function(function () use ($worker) { |
|
214 | + register_shutdown_function(function() use ($worker) { |
|
215 | 215 | if (!$worker->hasTask()) { |
216 | 216 | return; |
217 | 217 | } |
@@ -251,14 +251,14 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function sendSignalToMaster($sig = SIGTERM) |
253 | 253 | { |
254 | - $this->log->info('----> sending signal to master. signal: ' . $sig); |
|
254 | + $this->log->info('----> sending signal to master. signal: '.$sig); |
|
255 | 255 | posix_kill($this->master->getPid(), $sig); |
256 | 256 | $this->log->info('<---- sent signal.'); |
257 | 257 | |
258 | 258 | $this->log->info('----> waiting for master shutdown.'); |
259 | 259 | $status = null; |
260 | 260 | $this->pcntl->waitpid($this->master->getPid(), $status); |
261 | - $this->log->info('<---- master shutdown. status: ' . $status); |
|
261 | + $this->log->info('<---- master shutdown. status: '.$status); |
|
262 | 262 | $this->master = null; |
263 | 263 | } |
264 | 264 |