Completed
Pull Request — master (#19)
by Akihito
01:39
created
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.