@@ -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 | */ |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | try { |
114 | 114 | $this->master = $this->pcntl->fork(); |
115 | 115 | } catch (\RuntimeException $e) { |
116 | - $message = 'failed to fork master: ' . $e->getMessage(); |
|
116 | + $message = 'failed to fork master: '.$e->getMessage(); |
|
117 | 117 | $this->log->error($message); |
118 | 118 | throw new \RuntimeException($message); |
119 | 119 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | if (getmypid() === $this->config->get('ownerPid')) { |
124 | 124 | // owner |
125 | - $this->log->info('pid: ' . getmypid()); |
|
125 | + $this->log->info('pid: '.getmypid()); |
|
126 | 126 | $this->taskQueue = $this->queueFactory->createTaskQueue(); |
127 | 127 | $this->resultQueue = $this->queueFactory->createResultQueue(); |
128 | 128 | |
@@ -130,17 +130,17 @@ discard block |
||
130 | 130 | } else { |
131 | 131 | // master |
132 | 132 | $activeWorkerSet = new ActiveWorkerSet(); |
133 | - $this->log->info('pid: ' . $this->master->getPid()); |
|
133 | + $this->log->info('pid: '.$this->master->getPid()); |
|
134 | 134 | |
135 | 135 | foreach ($this->signals as $sig) { |
136 | - $this->pcntl->signal($sig, function ($sig) use ($activeWorkerSet) { |
|
136 | + $this->pcntl->signal($sig, function($sig) use ($activeWorkerSet) { |
|
137 | 137 | $this->receivedSignal = $sig; |
138 | - $this->log->info('received signal: ' . $sig); |
|
138 | + $this->log->info('received signal: '.$sig); |
|
139 | 139 | |
140 | 140 | if ($activeWorkerSet->count() === 0) { |
141 | 141 | $this->log->info('no worker is active.'); |
142 | 142 | } else { |
143 | - $this->log->info('------> sending signal to workers. signal: ' . $sig); |
|
143 | + $this->log->info('------> sending signal to workers. signal: '.$sig); |
|
144 | 144 | $activeWorkerSet->terminate($sig); |
145 | 145 | $this->log->info('<------ sent signal'); |
146 | 146 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | }); |
149 | 149 | } |
150 | 150 | |
151 | - $concurrency = (int)$this->config->get('concurrency'); |
|
151 | + $concurrency = (int) $this->config->get('concurrency'); |
|
152 | 152 | for ($i = 0; $i < $concurrency; $i++) { |
153 | 153 | $activeWorkerSet->add($this->forkWorker()); |
154 | 154 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | try { |
178 | 178 | $process = $this->pcntl->fork(); |
179 | 179 | } catch (\RuntimeException $e) { |
180 | - $message = 'failed to fork worker: ' . $e->getMessage(); |
|
180 | + $message = 'failed to fork worker: '.$e->getMessage(); |
|
181 | 181 | $this->log->error($message); |
182 | 182 | throw new \RuntimeException($message); |
183 | 183 | } |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | |
187 | 187 | if (getmypid() === $this->master->getPid()) { |
188 | 188 | // master |
189 | - $this->log->info('forked worker. pid: ' . $worker->getPid()); |
|
189 | + $this->log->info('forked worker. pid: '.$worker->getPid()); |
|
190 | 190 | return $worker; |
191 | 191 | } else { |
192 | 192 | // worker |
193 | 193 | // @codeCoverageIgnoreStart |
194 | - $this->log->info('has forked. pid: ' . getmypid()); |
|
194 | + $this->log->info('has forked. pid: '.getmypid()); |
|
195 | 195 | |
196 | 196 | foreach ($this->signals as $sig) { |
197 | - $this->pcntl->signal($sig, function ($sig) { |
|
197 | + $this->pcntl->signal($sig, function($sig) { |
|
198 | 198 | $this->receivedSignal = $sig; |
199 | 199 | exit; |
200 | 200 | }, false); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | $worker->setTaskQueue($this->queueFactory->createTaskQueue()); |
204 | 204 | $worker->setResultQueue($this->queueFactory->createResultQueue()); |
205 | 205 | |
206 | - register_shutdown_function(function () use ($worker) { |
|
206 | + register_shutdown_function(function() use ($worker) { |
|
207 | 207 | if (!$worker->hasTask()) { |
208 | 208 | return; |
209 | 209 | } |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function sendSignalToMaster($sig = SIGTERM) |
245 | 245 | { |
246 | - $this->log->info('----> sending signal to master. signal: ' . $sig); |
|
246 | + $this->log->info('----> sending signal to master. signal: '.$sig); |
|
247 | 247 | posix_kill($this->master->getPid(), $sig); |
248 | 248 | $this->log->info('<---- sent signal.'); |
249 | 249 | |
250 | 250 | $this->log->info('----> waiting for master shutdown.'); |
251 | 251 | $status = null; |
252 | 252 | $this->pcntl->waitpid($this->master->getPid(), $status); |
253 | - $this->log->info('<---- master shutdown. status: ' . $status); |
|
253 | + $this->log->info('<---- master shutdown. status: '.$status); |
|
254 | 254 | $this->master = null; |
255 | 255 | } |
256 | 256 |
@@ -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 | } |