@@ -26,7 +26,7 @@ |
||
26 | 26 | public function toArray() |
27 | 27 | { |
28 | 28 | return array_map( |
29 | - function ($result) { |
|
29 | + function($result) { |
|
30 | 30 | return $result->getReturn(); |
31 | 31 | }, |
32 | 32 | $this->results |
@@ -20,7 +20,7 @@ |
||
20 | 20 | { |
21 | 21 | $this->ownerPid = $ownerPid; |
22 | 22 | $this->prefix = $prefix; |
23 | - $this->pathname = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $this->prefix . $this->ownerPid; |
|
23 | + $this->pathname = sys_get_temp_dir().DIRECTORY_SEPARATOR.$this->prefix.$this->ownerPid; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -declare(ticks=1); |
|
2 | +declare(ticks = 1); |
|
3 | 3 | |
4 | 4 | namespace Ackintosh\Snidel; |
5 | 5 |
@@ -53,6 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @param int $ownerPid |
56 | + * @param \Ackintosh\Snidel\Log $log |
|
56 | 57 | */ |
57 | 58 | public function __construct($ownerPid, $log, Config $config) |
58 | 59 | { |
@@ -66,6 +67,7 @@ discard block |
||
66 | 67 | |
67 | 68 | /** |
68 | 69 | * @param \Ackintosh\Snidel\Task |
70 | + * @param \Ackintosh\Snidel\Task\Task $task |
|
69 | 71 | * @return void |
70 | 72 | * @throws \RuntimeException |
71 | 73 | */ |
@@ -310,6 +312,9 @@ discard block |
||
310 | 312 | } |
311 | 313 | } |
312 | 314 | |
315 | + /** |
|
316 | + * @param string $tag |
|
317 | + */ |
|
313 | 318 | public function getCollection($tag = null) |
314 | 319 | { |
315 | 320 | if ($tag === null) { |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | if (getmypid() === $this->ownerPid) { |
148 | 148 | // owner |
149 | - $this->log->info('pid: ' . getmypid()); |
|
149 | + $this->log->info('pid: '.getmypid()); |
|
150 | 150 | $this->taskQueue = $this->queueFactory->createTaskQueue(); |
151 | 151 | $this->resultQueue = $this->queueFactory->createResultQueue(); |
152 | 152 | |
@@ -154,18 +154,18 @@ discard block |
||
154 | 154 | } else { |
155 | 155 | // master |
156 | 156 | $activeWorkerSet = new ActiveWorkerSet(); |
157 | - $this->log->info('pid: ' . $this->masterPid); |
|
157 | + $this->log->info('pid: '.$this->masterPid); |
|
158 | 158 | |
159 | 159 | $receivedSignal = &$this->receivedSignal; |
160 | 160 | foreach ($this->signals as $sig) { |
161 | - $this->pcntl->signal($sig, function ($sig) use ($activeWorkerSet, $receivedSignal) { |
|
161 | + $this->pcntl->signal($sig, function($sig) use ($activeWorkerSet, $receivedSignal) { |
|
162 | 162 | $receivedSignal = $sig; |
163 | - $this->log->info('received signal: ' . $sig); |
|
163 | + $this->log->info('received signal: '.$sig); |
|
164 | 164 | |
165 | 165 | if ($activeWorkerSet->count() === 0) { |
166 | 166 | $this->log->info('no worker is active.'); |
167 | 167 | } else { |
168 | - $this->log->info('------> sending signal to workers. signal: ' . $sig); |
|
168 | + $this->log->info('------> sending signal to workers. signal: '.$sig); |
|
169 | 169 | $activeWorkerSet->terminate($sig); |
170 | 170 | $this->log->info('<------ sent signal'); |
171 | 171 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | }); |
174 | 174 | } |
175 | 175 | |
176 | - $concurrency = (int)$this->config->get('concurrency'); |
|
176 | + $concurrency = (int) $this->config->get('concurrency'); |
|
177 | 177 | for ($i = 0; $i < $concurrency; $i++) { |
178 | 178 | $activeWorkerSet->add($this->forkWorker()); |
179 | 179 | } |
@@ -210,17 +210,17 @@ discard block |
||
210 | 210 | |
211 | 211 | if (getmypid() === $this->masterPid) { |
212 | 212 | // master |
213 | - $this->log->info('forked worker. pid: ' . $worker->getPid()); |
|
213 | + $this->log->info('forked worker. pid: '.$worker->getPid()); |
|
214 | 214 | return $worker; |
215 | 215 | } else { |
216 | 216 | // worker |
217 | 217 | // @codeCoverageIgnoreStart |
218 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
218 | + $this->log->info('has forked. pid: '.getmypid()); |
|
219 | 219 | |
220 | 220 | // for php5.3 |
221 | 221 | $receivedSignal = &$this->receivedSignal; |
222 | 222 | foreach ($this->signals as $sig) { |
223 | - $this->pcntl->signal($sig, function ($sig) use ($receivedSignal) { |
|
223 | + $this->pcntl->signal($sig, function($sig) use ($receivedSignal) { |
|
224 | 224 | $receivedSignal = $sig; |
225 | 225 | exit; |
226 | 226 | }, false); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $worker->setTaskQueue($this->queueFactory->createTaskQueue()); |
230 | 230 | $worker->setResultQueue($this->queueFactory->createResultQueue()); |
231 | 231 | |
232 | - register_shutdown_function(function () use ($worker, $receivedSignal) { |
|
232 | + register_shutdown_function(function() use ($worker, $receivedSignal) { |
|
233 | 233 | if ($worker->isFailedToEnqueueResult() && $receivedSignal === null) { |
234 | 234 | $worker->error(); |
235 | 235 | } |
@@ -265,14 +265,14 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function sendSignalToMaster($sig = SIGTERM) |
267 | 267 | { |
268 | - $this->log->info('----> sending signal to master. signal: ' . $sig); |
|
268 | + $this->log->info('----> sending signal to master. signal: '.$sig); |
|
269 | 269 | posix_kill($this->masterPid, $sig); |
270 | 270 | $this->log->info('<---- sent signal.'); |
271 | 271 | |
272 | 272 | $this->log->info('----> waiting for master shutdown.'); |
273 | 273 | $status = null; |
274 | 274 | $this->pcntl->waitpid($this->masterPid, $status); |
275 | - $this->log->info('<---- master shutdown. status: ' . $status); |
|
275 | + $this->log->info('<---- master shutdown. status: '.$status); |
|
276 | 276 | $this->masterPid = null; |
277 | 277 | } |
278 | 278 |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | foreach ($this->signals as $sig) { |
65 | 65 | $this->pcntl->signal( |
66 | 66 | $sig, |
67 | - function ($sig) { |
|
68 | - $this->log->info('received signal. signo: ' . $sig); |
|
67 | + function($sig) { |
|
68 | + $this->log->info('received signal. signo: '.$sig); |
|
69 | 69 | $this->setReceivedSignal($sig); |
70 | 70 | |
71 | 71 | $this->log->info('--> sending a signal " to children.'); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | ); |
78 | 78 | } |
79 | 79 | |
80 | - $this->log->info('parent pid: ' . $this->ownerPid); |
|
80 | + $this->log->info('parent pid: '.$this->ownerPid); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | throw $e; |
116 | 116 | } |
117 | 117 | |
118 | - $this->log->info('queued task #' . $this->container->queuedCount()); |
|
118 | + $this->log->info('queued task #'.$this->container->queuedCount()); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $this->wait(); |
159 | 159 | } |
160 | 160 | if ($tag !== null && !$this->container->hasTag($tag)) { |
161 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
161 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return $this->container->getCollection($tag); |
@@ -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'; |