@@ -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'; |
@@ -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 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $this->container = new Container($this->config, $this->log); |
38 | 38 | $this->container->forkMaster(); |
39 | 39 | $this->registerSignalHandler($this->container, $this->log); |
40 | - $this->log->info('parent pid: ' . $this->config->get('ownerPid')); |
|
40 | + $this->log->info('parent pid: '.$this->config->get('ownerPid')); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | try { |
55 | 55 | $this->container->enqueue(new Task($callable, $args, $tag)); |
56 | 56 | } catch (\RuntimeException $e) { |
57 | - $this->log->error('failed to enqueue the task: ' . $e->getMessage()); |
|
57 | + $this->log->error('failed to enqueue the task: '.$e->getMessage()); |
|
58 | 58 | throw $e; |
59 | 59 | } |
60 | 60 | |
61 | - $this->log->info('queued task #' . $this->container->queuedCount()); |
|
61 | + $this->log->info('queued task #'.$this->container->queuedCount()); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function results() |
80 | 80 | { |
81 | - foreach($this->container->results() as $r) { |
|
81 | + foreach ($this->container->results() as $r) { |
|
82 | 82 | yield $r; |
83 | 83 | } |
84 | 84 | } |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | foreach ($this->signals as $sig) { |
110 | 110 | $pcntl->signal( |
111 | 111 | $sig, |
112 | - function ($sig) use ($log, $container) { |
|
113 | - $log->info('received signal. signo: ' . $sig); |
|
112 | + function($sig) use ($log, $container) { |
|
113 | + $log->info('received signal. signo: '.$sig); |
|
114 | 114 | $log->info('--> sending a signal " to children.'); |
115 | 115 | $container->sendSignalToMaster($sig); |
116 | 116 | $log->info('<-- signal handling has been completed successfully.'); |