@@ -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'; |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | private $receivedSignal; |
46 | 46 | |
47 | 47 | /** |
48 | - * @param int $ownerPid |
|
48 | + * @param \Ackintosh\Snidel\Log $log |
|
49 | 49 | */ |
50 | 50 | public function __construct(Config $config, $log) |
51 | 51 | { |
@@ -58,6 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @param \Ackintosh\Snidel\Task |
61 | + * @param \Ackintosh\Snidel\Task\Task $task |
|
61 | 62 | * @return void |
62 | 63 | * @throws \RuntimeException |
63 | 64 | */ |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | if (getmypid() === $this->config->get('ownerPid')) { |
140 | 140 | // owner |
141 | - $this->log->info('pid: ' . getmypid()); |
|
141 | + $this->log->info('pid: '.getmypid()); |
|
142 | 142 | $this->taskQueue = $this->queueFactory->createTaskQueue(); |
143 | 143 | $this->resultQueue = $this->queueFactory->createResultQueue(); |
144 | 144 | |
@@ -146,17 +146,17 @@ discard block |
||
146 | 146 | } else { |
147 | 147 | // master |
148 | 148 | $activeWorkerSet = new ActiveWorkerSet(); |
149 | - $this->log->info('pid: ' . $this->masterPid); |
|
149 | + $this->log->info('pid: '.$this->masterPid); |
|
150 | 150 | |
151 | 151 | foreach ($this->signals as $sig) { |
152 | - $this->pcntl->signal($sig, function ($sig) use ($activeWorkerSet) { |
|
152 | + $this->pcntl->signal($sig, function($sig) use ($activeWorkerSet) { |
|
153 | 153 | $this->receivedSignal = $sig; |
154 | - $this->log->info('received signal: ' . $sig); |
|
154 | + $this->log->info('received signal: '.$sig); |
|
155 | 155 | |
156 | 156 | if ($activeWorkerSet->count() === 0) { |
157 | 157 | $this->log->info('no worker is active.'); |
158 | 158 | } else { |
159 | - $this->log->info('------> sending signal to workers. signal: ' . $sig); |
|
159 | + $this->log->info('------> sending signal to workers. signal: '.$sig); |
|
160 | 160 | $activeWorkerSet->terminate($sig); |
161 | 161 | $this->log->info('<------ sent signal'); |
162 | 162 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | }); |
165 | 165 | } |
166 | 166 | |
167 | - $concurrency = (int)$this->config->get('concurrency'); |
|
167 | + $concurrency = (int) $this->config->get('concurrency'); |
|
168 | 168 | for ($i = 0; $i < $concurrency; $i++) { |
169 | 169 | $activeWorkerSet->add($this->forkWorker()); |
170 | 170 | } |
@@ -201,15 +201,15 @@ 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 | - $this->pcntl->signal($sig, function ($sig) { |
|
212 | + $this->pcntl->signal($sig, function($sig) { |
|
213 | 213 | $this->receivedSignal = $sig; |
214 | 214 | exit; |
215 | 215 | }, false); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $worker->setTaskQueue($this->queueFactory->createTaskQueue()); |
219 | 219 | $worker->setResultQueue($this->queueFactory->createResultQueue()); |
220 | 220 | |
221 | - register_shutdown_function(function () use ($worker) { |
|
221 | + register_shutdown_function(function() use ($worker) { |
|
222 | 222 | if ($worker->isFailedToEnqueueResult() && $this->receivedSignal === null) { |
223 | 223 | $worker->error(); |
224 | 224 | } |
@@ -254,14 +254,14 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function sendSignalToMaster($sig = SIGTERM) |
256 | 256 | { |
257 | - $this->log->info('----> sending signal to master. signal: ' . $sig); |
|
257 | + $this->log->info('----> sending signal to master. signal: '.$sig); |
|
258 | 258 | posix_kill($this->masterPid, $sig); |
259 | 259 | $this->log->info('<---- sent signal.'); |
260 | 260 | |
261 | 261 | $this->log->info('----> waiting for master shutdown.'); |
262 | 262 | $status = null; |
263 | 263 | $this->pcntl->waitpid($this->masterPid, $status); |
264 | - $this->log->info('<---- master shutdown. status: ' . $status); |
|
264 | + $this->log->info('<---- master shutdown. status: '.$status); |
|
265 | 265 | $this->masterPid = null; |
266 | 266 | } |
267 | 267 |
@@ -23,7 +23,7 @@ |
||
23 | 23 | { |
24 | 24 | $this->ownerPid = $ownerPid; |
25 | 25 | $this->prefix = $prefix; |
26 | - $this->pathname = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $this->prefix . $this->ownerPid; |
|
26 | + $this->pathname = sys_get_temp_dir().DIRECTORY_SEPARATOR.$this->prefix.$this->ownerPid; |
|
27 | 27 | $this->semaphore = new Semaphore(); |
28 | 28 | } |
29 | 29 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(ticks=1); |
|
2 | +declare(ticks = 1); |
|
3 | 3 | |
4 | 4 | namespace Ackintosh\Snidel; |
5 | 5 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | public function __construct(Config $config) |
30 | 30 | { |
31 | 31 | $this->ownerPid = $config->get('ownerPid'); |
32 | - $this->ipcKey = new IpcKey($this->ownerPid, $config->get('id') . str_replace('\\', '_', get_class($this))); |
|
32 | + $this->ipcKey = new IpcKey($this->ownerPid, $config->get('id').str_replace('\\', '_', get_class($this))); |
|
33 | 33 | $this->semaphore = new Semaphore(); |
34 | 34 | $this->id = $this->semaphore->getQueue($this->ipcKey->generate()); |
35 | 35 | $this->stat = $this->semaphore->statQueue($this->id); |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | foreach ($this->signals as $sig) { |
43 | 43 | $this->pcntl->signal( |
44 | 44 | $sig, |
45 | - function ($sig) { |
|
46 | - $this->log->info('received signal. signo: ' . $sig); |
|
45 | + function($sig) { |
|
46 | + $this->log->info('received signal. signo: '.$sig); |
|
47 | 47 | $this->log->info('--> sending a signal " to children.'); |
48 | 48 | $this->container->sendSignalToMaster($sig); |
49 | 49 | $this->log->info('<-- signal handling has been completed successfully.'); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | ); |
54 | 54 | } |
55 | 55 | |
56 | - $this->log->info('parent pid: ' . $this->config->get('ownerPid')); |
|
56 | + $this->log->info('parent pid: '.$this->config->get('ownerPid')); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | throw $e; |
78 | 78 | } |
79 | 79 | |
80 | - $this->log->info('queued task #' . $this->container->queuedCount()); |
|
80 | + $this->log->info('queued task #'.$this->container->queuedCount()); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function results() |
99 | 99 | { |
100 | - foreach($this->container->results() as $r) { |
|
100 | + foreach ($this->container->results() as $r) { |
|
101 | 101 | yield $r; |
102 | 102 | } |
103 | 103 | } |