Completed
Pull Request — master (#19)
by Akihito
01:39
created
src/Snidel/Log.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
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';
Please login to merge, or discard this patch.
src/Snidel/IpcKey.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Snidel/AbstractQueue.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/Snidel.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/Snidel/Fork/Container.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         try {
126 126
             $this->master = $this->pcntl->fork();
127 127
         } catch (\RuntimeException $e) {
128
-            $message = 'failed to fork master: ' . $e->getMessage();
128
+            $message = 'failed to fork master: '.$e->getMessage();
129 129
             $this->log->error($message);
130 130
             throw new \RuntimeException($message);
131 131
         }
@@ -134,24 +134,24 @@  discard block
 block discarded – undo
134 134
 
135 135
         if (getmypid() === $this->config->get('ownerPid')) {
136 136
             // owner
137
-            $this->log->info('pid: ' . getmypid());
138
-            $this->resultQueue  = $this->factory->create('result');
137
+            $this->log->info('pid: '.getmypid());
138
+            $this->resultQueue = $this->factory->create('result');
139 139
 
140 140
             return $this->master;
141 141
         } else {
142 142
             // master
143 143
             $activeWorkerSet = new ActiveWorkerSet();
144
-            $this->log->info('pid: ' . $this->master->getPid());
144
+            $this->log->info('pid: '.$this->master->getPid());
145 145
 
146 146
             foreach ($this->signals as $sig) {
147
-                $this->pcntl->signal($sig, function ($sig) use ($activeWorkerSet) {
147
+                $this->pcntl->signal($sig, function($sig) use ($activeWorkerSet) {
148 148
                     $this->receivedSignal = $sig;
149
-                    $this->log->info('received signal: ' . $sig);
149
+                    $this->log->info('received signal: '.$sig);
150 150
 
151 151
                     if ($activeWorkerSet->count() === 0) {
152 152
                         $this->log->info('no worker is active.');
153 153
                     } else {
154
-                        $this->log->info('------> sending signal to workers. signal: ' . $sig);
154
+                        $this->log->info('------> sending signal to workers. signal: '.$sig);
155 155
                         $activeWorkerSet->terminate($sig);
156 156
                         $this->log->info('<------ sent signal');
157 157
                     }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                 });
160 160
             }
161 161
 
162
-            $concurrency = (int)$this->config->get('concurrency');
162
+            $concurrency = (int) $this->config->get('concurrency');
163 163
             for ($i = 0; $i < $concurrency; $i++) {
164 164
                 $activeWorkerSet->add($this->forkWorker());
165 165
             }
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         try {
189 189
             $process = $this->pcntl->fork();
190 190
         } catch (\RuntimeException $e) {
191
-            $message = 'failed to fork worker: ' . $e->getMessage();
191
+            $message = 'failed to fork worker: '.$e->getMessage();
192 192
             $this->log->error($message);
193 193
             throw new \RuntimeException($message);
194 194
         }
@@ -197,21 +197,21 @@  discard block
 block discarded – undo
197 197
 
198 198
         if (getmypid() === $this->master->getPid()) {
199 199
             // master
200
-            $this->log->info('forked worker. pid: ' . $worker->getPid());
200
+            $this->log->info('forked worker. pid: '.$worker->getPid());
201 201
             return $worker;
202 202
         } else {
203 203
             // worker
204 204
             // @codeCoverageIgnoreStart
205
-            $this->log->info('has forked. pid: ' . getmypid());
205
+            $this->log->info('has forked. pid: '.getmypid());
206 206
 
207 207
             foreach ($this->signals as $sig) {
208
-                $this->pcntl->signal($sig, function ($sig) {
208
+                $this->pcntl->signal($sig, function($sig) {
209 209
                     $this->receivedSignal = $sig;
210 210
                     exit;
211 211
                 }, false);
212 212
             }
213 213
 
214
-            register_shutdown_function(function () use ($worker) {
214
+            register_shutdown_function(function() use ($worker) {
215 215
                 if ($this->receivedSignal === null && $worker->isInProgress()) {
216 216
                     $worker->error();
217 217
                 }
@@ -247,14 +247,14 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function sendSignalToMaster($sig = SIGTERM)
249 249
     {
250
-        $this->log->info('----> sending signal to master. signal: ' . $sig);
250
+        $this->log->info('----> sending signal to master. signal: '.$sig);
251 251
         posix_kill($this->master->getPid(), $sig);
252 252
         $this->log->info('<---- sent signal.');
253 253
 
254 254
         $this->log->info('----> waiting for master shutdown.');
255 255
         $status = null;
256 256
         $this->pcntl->waitpid($this->master->getPid(), $status);
257
-        $this->log->info('<---- master shutdown. status: ' . $status);
257
+        $this->log->info('<---- master shutdown. status: '.$status);
258 258
         $this->master = null;
259 259
     }
260 260
 
Please login to merge, or discard this patch.
src/Snidel/Config.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.