@@ -20,7 +20,7 @@ |
||
20 | 20 | public function toArray() |
21 | 21 | { |
22 | 22 | return array_map( |
23 | - function ($fork) { |
|
23 | + function($fork) { |
|
24 | 24 | return $fork->getResult()->getReturn(); |
25 | 25 | }, |
26 | 26 | $this->forks |
@@ -49,7 +49,7 @@ |
||
49 | 49 | $type, |
50 | 50 | $pid, |
51 | 51 | ($this->ownerPid === $pid) ? 'p' : 'c', |
52 | - $message . PHP_EOL |
|
52 | + $message.PHP_EOL |
|
53 | 53 | ) |
54 | 54 | ); |
55 | 55 | } |
@@ -50,15 +50,15 @@ |
||
50 | 50 | } |
51 | 51 | $pid = getmypid(); |
52 | 52 | switch (true) { |
53 | - case $this->ownerPid === $pid: |
|
54 | - $role = 'owner'; |
|
55 | - break; |
|
56 | - case $this->masterPid === $pid: |
|
57 | - $role = 'master'; |
|
58 | - break; |
|
59 | - default: |
|
60 | - $role = 'worker'; |
|
61 | - break; |
|
53 | + case $this->ownerPid === $pid: |
|
54 | + $role = 'owner'; |
|
55 | + break; |
|
56 | + case $this->masterPid === $pid: |
|
57 | + $role = 'master'; |
|
58 | + break; |
|
59 | + default: |
|
60 | + $role = 'worker'; |
|
61 | + break; |
|
62 | 62 | } |
63 | 63 | fputs( |
64 | 64 | $this->destination, |
@@ -28,7 +28,7 @@ |
||
28 | 28 | { |
29 | 29 | $this->ownerPid = $ownerPid; |
30 | 30 | $this->concurrency = $concurrency; |
31 | - $this->ipcKey = new IpcKey($ownerPid, 'snidel_token_' . uniqid((string) mt_rand(1, 100), true)); |
|
31 | + $this->ipcKey = new IpcKey($ownerPid, 'snidel_token_'.uniqid((string) mt_rand(1, 100), true)); |
|
32 | 32 | $this->id = msg_get_queue($this->ipcKey->generate()); |
33 | 33 | $this->initializeQueue(); |
34 | 34 | } |
@@ -137,6 +137,6 @@ |
||
137 | 137 | return $index; |
138 | 138 | } |
139 | 139 | |
140 | - throw new MapContainerException('childPid not found. pid: ' . $childPid); |
|
140 | + throw new MapContainerException('childPid not found. pid: '.$childPid); |
|
141 | 141 | } |
142 | 142 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function generate() |
28 | 28 | { |
29 | - $pathname = '/tmp/' . $this->prefix . $this->ownerPid; |
|
29 | + $pathname = '/tmp/'.$this->prefix.$this->ownerPid; |
|
30 | 30 | if (!file_exists($pathname)) { |
31 | 31 | touch($pathname); |
32 | 32 | } |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function delete() |
54 | 54 | { |
55 | - if (file_exists('/tmp/' . $this->prefix . $this->ownerPid)) { |
|
56 | - unlink('/tmp/' . $this->prefix . $this->ownerPid); |
|
55 | + if (file_exists('/tmp/'.$this->prefix.$this->ownerPid)) { |
|
56 | + unlink('/tmp/'.$this->prefix.$this->ownerPid); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
@@ -45,6 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param int $ownerPid |
48 | + * @param Log $log |
|
48 | 49 | */ |
49 | 50 | public function __construct($ownerPid, $log, $concurrency = 5) |
50 | 51 | { |
@@ -60,6 +61,7 @@ discard block |
||
60 | 61 | |
61 | 62 | /** |
62 | 63 | * @param \Ackintosh\Snidel\Task |
64 | + * @param Task $task |
|
63 | 65 | * @return void |
64 | 66 | */ |
65 | 67 | public function enqueue($task) |
@@ -155,6 +157,7 @@ discard block |
||
155 | 157 | * fork worker process |
156 | 158 | * |
157 | 159 | * @param \Ackintosh\Snidel\Task |
160 | + * @param Task $task |
|
158 | 161 | * @return void |
159 | 162 | * @throws \RuntimeException |
160 | 163 | */ |
@@ -262,7 +265,7 @@ discard block |
||
262 | 265 | } |
263 | 266 | |
264 | 267 | /** |
265 | - * @return array |
|
268 | + * @return integer[] |
|
266 | 269 | */ |
267 | 270 | public function getChildPids() |
268 | 271 | { |
@@ -280,6 +283,9 @@ discard block |
||
280 | 283 | return $this->forks[$pid]; |
281 | 284 | } |
282 | 285 | |
286 | + /** |
|
287 | + * @param string $tag |
|
288 | + */ |
|
283 | 289 | public function getCollection($tag = null) |
284 | 290 | { |
285 | 291 | if ($tag === null) { |
@@ -293,7 +299,7 @@ discard block |
||
293 | 299 | * return forks |
294 | 300 | * |
295 | 301 | * @param string $tag |
296 | - * @return \Ackintosh\Snidel\Fork[] |
|
302 | + * @return ForkCollection |
|
297 | 303 | */ |
298 | 304 | private function getCollectionWithTag($tag) |
299 | 305 | { |
@@ -313,7 +319,7 @@ discard block |
||
313 | 319 | } |
314 | 320 | |
315 | 321 | /** |
316 | - * @return \Ackintosh\Sniden\Error |
|
322 | + * @return Error |
|
317 | 323 | */ |
318 | 324 | public function getError() |
319 | 325 | { |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | |
130 | 130 | if ($pid) { |
131 | 131 | // owner |
132 | - $this->log->info('pid: ' . getmypid()); |
|
132 | + $this->log->info('pid: '.getmypid()); |
|
133 | 133 | |
134 | 134 | return $this->masterPid; |
135 | 135 | } elseif ($pid === -1) { |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | } else { |
138 | 138 | // master |
139 | 139 | $taskQueue = new TaskQueue($this->ownerPid); |
140 | - $this->log->info('pid: ' . $this->masterPid); |
|
140 | + $this->log->info('pid: '.$this->masterPid); |
|
141 | 141 | |
142 | 142 | foreach ($this->signals as $sig) { |
143 | 143 | $this->pcntl->signal($sig, SIG_DFL, true); |
144 | 144 | } |
145 | 145 | |
146 | 146 | while ($task = $taskQueue->dequeue()) { |
147 | - $this->log->info('dequeued task #' . $taskQueue->dequeuedCount()); |
|
147 | + $this->log->info('dequeued task #'.$taskQueue->dequeuedCount()); |
|
148 | 148 | if ($this->token->accept()) { |
149 | 149 | $this->forkWorker($task); |
150 | 150 | } |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | |
172 | 172 | if (getmypid() === $this->masterPid) { |
173 | 173 | // master |
174 | - $this->log->info('forked worker. pid: ' . $fork->getPid()); |
|
174 | + $this->log->info('forked worker. pid: '.$fork->getPid()); |
|
175 | 175 | } else { |
176 | 176 | // worker |
177 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
177 | + $this->log->info('has forked. pid: '.getmypid()); |
|
178 | 178 | // @codeCoverageIgnoreStart |
179 | 179 | |
180 | 180 | foreach ($this->signals as $sig) { |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | $resultQueue = new ResultQueue($this->ownerPid); |
185 | - register_shutdown_function(function () use ($fork, $resultQueue) { |
|
185 | + register_shutdown_function(function() use ($fork, $resultQueue) { |
|
186 | 186 | if ($fork->hasNoResult() || !$fork->isQueued()) { |
187 | 187 | $result = new Result(); |
188 | 188 | $result->setFailure(); |
@@ -315,8 +315,8 @@ discard block |
||
315 | 315 | */ |
316 | 316 | private function getCollectionWithTag($tag) |
317 | 317 | { |
318 | - $collection = array_filter($this->forks, function ($fork) use ($tag) { |
|
319 | - return $fork->getTag() === $tag; |
|
318 | + $collection = array_filter($this->forks, function($fork) use ($tag) { |
|
319 | + return $fork->getTag() === $tag; |
|
320 | 320 | }); |
321 | 321 | |
322 | 322 | return new ForkCollection($collection); |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | foreach ($this->signals as $sig) { |
65 | 65 | $this->pcntl->signal( |
66 | 66 | $sig, |
67 | - function ($sig) use($log, $self) { |
|
68 | - $log->info('received signal. signo: ' . $sig); |
|
67 | + function($sig) use($log, $self) { |
|
68 | + $log->info('received signal. signo: '.$sig); |
|
69 | 69 | $self->setReceivedSignal($sig); |
70 | 70 | |
71 | 71 | $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 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | throw $e; |
114 | 114 | } |
115 | 115 | |
116 | - $this->log->info('queued task #' . $this->forkContainer->queuedCount()); |
|
116 | + $this->log->info('queued task #'.$this->forkContainer->queuedCount()); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | if (getmypid() === $this->ownerPid) { |
142 | 142 | // parent |
143 | - $this->log->info('created child process. pid: ' . $fork->getPid()); |
|
143 | + $this->log->info('created child process. pid: '.$fork->getPid()); |
|
144 | 144 | } else { |
145 | 145 | // @codeCoverageIgnoreStart |
146 | 146 | // child |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * in php5.3, we can not use $this in anonymous functions |
153 | 153 | */ |
154 | 154 | $log = $this->log; |
155 | - register_shutdown_function(function () use ($fork, $log, $token) { |
|
155 | + register_shutdown_function(function() use ($fork, $log, $token) { |
|
156 | 156 | $dataRepository = new DataRepository(); |
157 | 157 | $data = $dataRepository->load(getmypid()); |
158 | 158 | try { |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $this->wait(); |
219 | 219 | } |
220 | 220 | if (!$this->forkContainer->hasTag($tag)) { |
221 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
221 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | return $this->forkContainer->getCollection($tag); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | public function sendSignalToChildren($sig) |
234 | 234 | { |
235 | 235 | foreach ($this->forkContainer->getChildPids() as $pid) { |
236 | - $this->log->info('----> sending a signal to child. pid: ' . $pid); |
|
236 | + $this->log->info('----> sending a signal to child. pid: '.$pid); |
|
237 | 237 | posix_kill($pid, $sig); |
238 | 238 | } |
239 | 239 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | |
338 | 338 | $childPid = $fork->getPid(); |
339 | 339 | if ($fork->hasNotFinishedSuccessfully()) { |
340 | - $message = 'an error has occurred in child process. pid: ' . $childPid; |
|
340 | + $message = 'an error has occurred in child process. pid: '.$childPid; |
|
341 | 341 | $this->log->error($message); |
342 | 342 | throw new \RuntimeException($message); |
343 | 343 | } |
@@ -8,6 +8,7 @@ |
||
8 | 8 | { |
9 | 9 | /** |
10 | 10 | * @param \Ackintosh\Snidel\Fork |
11 | + * @param Fork $fork |
|
11 | 12 | * @throws \RuntimeException |
12 | 13 | */ |
13 | 14 | public function enqueue($fork) |
@@ -18,7 +18,6 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @param callable $callable |
20 | 20 | * @param array $args |
21 | - * @param string $string |
|
22 | 21 | */ |
23 | 22 | public function __construct($callable, $args, $tag) |
24 | 23 | { |
@@ -44,7 +43,7 @@ discard block |
||
44 | 43 | } |
45 | 44 | |
46 | 45 | /** |
47 | - * @return string|null |
|
46 | + * @return string |
|
48 | 47 | */ |
49 | 48 | public function getTag() |
50 | 49 | { |
@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace Ackintosh\Snidel; |
3 | 3 | |
4 | 4 | use Ackintosh\Snidel\TaskInterface; |
5 | -use Ackintosh\Snidel\MinifiedTask; |
|
6 | 5 | |
7 | 6 | class Task implements TaskInterface |
8 | 7 | { |