@@ -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, |
@@ -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 |
@@ -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, $concurrency = 5) |
58 | 59 | { |
@@ -68,6 +69,7 @@ discard block |
||
68 | 69 | |
69 | 70 | /** |
70 | 71 | * @param \Ackintosh\Snidel\Task |
72 | + * @param \Ackintosh\Snidel\Task\Task $task |
|
71 | 73 | * @return void |
72 | 74 | * @throws \RuntimeException |
73 | 75 | */ |
@@ -89,7 +91,7 @@ discard block |
||
89 | 91 | } |
90 | 92 | |
91 | 93 | /** |
92 | - * @return \Ackintosh\Snidel\Fork\Fork |
|
94 | + * @return Result |
|
93 | 95 | */ |
94 | 96 | private function dequeue() |
95 | 97 | { |
@@ -293,6 +295,9 @@ discard block |
||
293 | 295 | } |
294 | 296 | } |
295 | 297 | |
298 | + /** |
|
299 | + * @param string $tag |
|
300 | + */ |
|
296 | 301 | public function getCollection($tag = null) |
297 | 302 | { |
298 | 303 | if ($tag === null) { |
@@ -335,7 +340,7 @@ discard block |
||
335 | 340 | } |
336 | 341 | |
337 | 342 | /** |
338 | - * @return \Ackintosh\Sniden\Error |
|
343 | + * @return Error |
|
339 | 344 | */ |
340 | 345 | public function getError() |
341 | 346 | { |
@@ -4,13 +4,10 @@ |
||
4 | 4 | use Ackintosh\Snidel\Config; |
5 | 5 | use Ackintosh\Snidel\Fork\Fork; |
6 | 6 | use Ackintosh\Snidel\Pcntl; |
7 | -use Ackintosh\Snidel\Task\Queue as TaskQueue; |
|
8 | 7 | use Ackintosh\Snidel\QueueFactory; |
9 | 8 | use Ackintosh\Snidel\Result\Result; |
10 | -use Ackintosh\Snidel\Result\Queue as ResultQueue; |
|
11 | 9 | use Ackintosh\Snidel\Result\Collection; |
12 | 10 | use Ackintosh\Snidel\Error; |
13 | -use Ackintosh\Snidel\Exception\SharedMemoryControlException; |
|
14 | 11 | use Ackintosh\Snidel\Worker; |
15 | 12 | use Ackintosh\Snidel\ActiveWorkerSet; |
16 | 13 |
@@ -140,24 +140,24 @@ discard block |
||
140 | 140 | |
141 | 141 | if (getmypid() === $this->ownerPid) { |
142 | 142 | // owner |
143 | - $this->log->info('pid: ' . getmypid()); |
|
143 | + $this->log->info('pid: '.getmypid()); |
|
144 | 144 | |
145 | 145 | return $this->masterPid; |
146 | 146 | } else { |
147 | 147 | // master |
148 | 148 | $taskQueue = $this->queueFactory->createTaskQueue(); |
149 | 149 | $activeWorkerSet = new ActiveWorkerSet(); |
150 | - $this->log->info('pid: ' . $this->masterPid); |
|
150 | + $this->log->info('pid: '.$this->masterPid); |
|
151 | 151 | |
152 | 152 | $log = $this->log; |
153 | 153 | foreach ($this->signals as $sig) { |
154 | - $this->pcntl->signal($sig, function ($sig) use ($log, $activeWorkerSet) { |
|
155 | - $log->info('received signal: ' . $sig); |
|
154 | + $this->pcntl->signal($sig, function($sig) use ($log, $activeWorkerSet) { |
|
155 | + $log->info('received signal: '.$sig); |
|
156 | 156 | |
157 | 157 | if ($activeWorkerSet->count() === 0) { |
158 | 158 | $log->info('no worker is active.'); |
159 | 159 | } else { |
160 | - $log->info('------> sending signal to workers. signal: ' . $sig); |
|
160 | + $log->info('------> sending signal to workers. signal: '.$sig); |
|
161 | 161 | $activeWorkerSet->terminate($sig); |
162 | 162 | $log->info('<------ sent signal'); |
163 | 163 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | }); |
166 | 166 | } |
167 | 167 | |
168 | - $concurrency = (int)$this->config->get('concurrency'); |
|
168 | + $concurrency = (int) $this->config->get('concurrency'); |
|
169 | 169 | while ($task = $taskQueue->dequeue()) { |
170 | - $this->log->info('dequeued task #' . $taskQueue->dequeuedCount()); |
|
170 | + $this->log->info('dequeued task #'.$taskQueue->dequeuedCount()); |
|
171 | 171 | if ($activeWorkerSet->count() >= $concurrency) { |
172 | 172 | $status = null; |
173 | 173 | $workerPid = $this->pcntl->waitpid(-1, $status); |
@@ -201,12 +201,12 @@ discard block |
||
201 | 201 | |
202 | 202 | if (getmypid() === $this->masterPid) { |
203 | 203 | // master |
204 | - $this->log->info('forked worker. pid: ' . $worker->getPid()); |
|
204 | + $this->log->info('forked worker. pid: '.$worker->getPid()); |
|
205 | 205 | return $worker; |
206 | 206 | } else { |
207 | 207 | // worker |
208 | 208 | // @codeCoverageIgnoreStart |
209 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
209 | + $this->log->info('has forked. pid: '.getmypid()); |
|
210 | 210 | |
211 | 211 | foreach ($this->signals as $sig) { |
212 | 212 | $this->pcntl->signal($sig, SIG_DFL, true); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $worker->setResultQueue($this->queueFactory->createResultQueue()); |
216 | 216 | |
217 | 217 | $resultHasQueued = false; |
218 | - register_shutdown_function(function () use (&$resultHasQueued, $worker) { |
|
218 | + register_shutdown_function(function() use (&$resultHasQueued, $worker) { |
|
219 | 219 | if (!$resultHasQueued) { |
220 | 220 | $worker->error(); |
221 | 221 | } |
@@ -252,13 +252,13 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function sendSignalToMaster($sig = SIGTERM) |
254 | 254 | { |
255 | - $this->log->info('----> sending signal to master. signal: ' . $sig); |
|
255 | + $this->log->info('----> sending signal to master. signal: '.$sig); |
|
256 | 256 | posix_kill($this->masterPid, $sig); |
257 | 257 | $this->log->info('<---- sent signal.'); |
258 | 258 | |
259 | 259 | $status = null; |
260 | 260 | $this->pcntl->waitpid($this->masterPid, $status); |
261 | - $this->log->info('. status: ' . $status); |
|
261 | + $this->log->info('. status: '.$status); |
|
262 | 262 | $this->masterPid = null; |
263 | 263 | } |
264 | 264 |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | foreach ($this->signals as $sig) { |
61 | 61 | $this->pcntl->signal( |
62 | 62 | $sig, |
63 | - function ($sig) use($log, $self) { |
|
64 | - $log->info('received signal. signo: ' . $sig); |
|
63 | + function($sig) use($log, $self) { |
|
64 | + $log->info('received signal. signo: '.$sig); |
|
65 | 65 | $self->setReceivedSignal($sig); |
66 | 66 | |
67 | 67 | $log->info('--> sending a signal " to children.'); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | ); |
74 | 74 | } |
75 | 75 | |
76 | - $this->log->info('parent pid: ' . $this->ownerPid); |
|
76 | + $this->log->info('parent pid: '.$this->ownerPid); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | throw $e; |
112 | 112 | } |
113 | 113 | |
114 | - $this->log->info('queued task #' . $this->container->queuedCount()); |
|
114 | + $this->log->info('queued task #'.$this->container->queuedCount()); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $this->wait(); |
155 | 155 | } |
156 | 156 | if ($tag !== null && !$this->container->hasTag($tag)) { |
157 | - throw new \InvalidArgumentException('unknown tag: ' . $tag); |
|
157 | + throw new \InvalidArgumentException('unknown tag: '.$tag); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return $this->container->getCollection($tag); |
@@ -7,10 +7,7 @@ |
||
7 | 7 | use Ackintosh\Snidel\Result\Result; |
8 | 8 | use Ackintosh\Snidel\Log; |
9 | 9 | use Ackintosh\Snidel\Pcntl; |
10 | -use Ackintosh\Snidel\DataRepository; |
|
11 | -use Ackintosh\Snidel\MapContainer; |
|
12 | 10 | use Ackintosh\Snidel\Task\Task; |
13 | -use Ackintosh\Snidel\Exception\SharedMemoryControlException; |
|
14 | 11 | |
15 | 12 | class Snidel |
16 | 13 | { |
@@ -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 | /** |