@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function __construct($tube = 'default', $port = '') |
| 38 | 38 | { |
| 39 | - $this->tube = str_replace("\\", '-', $tube);; |
|
| 39 | + $this->tube = str_replace("\\", '-', $tube); ; |
|
| 40 | 40 | $this->job_options = ['priority' => 250, 'delay' => 0, 'ttr' => 3600]; |
| 41 | 41 | $this->port = $port; |
| 42 | 42 | $this->reconnect(); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $config = $this->di->get('config')->beanstalk; |
| 51 | 51 | $port = $config->port; |
| 52 | - if(!empty($this->port) && is_numeric($this->port)){ |
|
| 52 | + if (!empty($this->port) && is_numeric($this->port)) { |
|
| 53 | 53 | $port = $this->port; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $tube = str_replace("\\", '-', $tube); |
| 128 | 128 | // Change tube |
| 129 | - if ( ! empty($tube) && $this->tube !== $tube) { |
|
| 129 | + if (!empty($tube) && $this->tube !== $tube) { |
|
| 130 | 130 | $this->queue->useTube($tube); |
| 131 | 131 | } |
| 132 | 132 | $job_data = serialize($job_data); |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Processing job over callable function attached in $this->subscribe |
| 181 | - if(json_decode($job->getData(), true) !==null){ |
|
| 182 | - $mData = $job->getData(); |
|
| 183 | - }else{ |
|
| 181 | + if (json_decode($job->getData(), true) !== null) { |
|
| 182 | + $mData = $job->getData(); |
|
| 183 | + } else { |
|
| 184 | 184 | $mData = unserialize($job->getData(), [false]); |
| 185 | 185 | } |
| 186 | 186 | $this->message = $mData; |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | try { |
| 199 | 199 | $this->queue->delete($job); |
| 200 | - }catch (\Pheanstalk\Exception\JobNotFoundException $e){ |
|
| 201 | - }catch (\Error $e){ |
|
| 200 | + } catch (\Pheanstalk\Exception\JobNotFoundException $e) { |
|
| 201 | + } catch (\Error $e) { |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
@@ -263,28 +263,28 @@ discard block |
||
| 263 | 263 | /** |
| 264 | 264 | * Drops orphaned tasks |
| 265 | 265 | */ |
| 266 | - public function cleanTube(){ |
|
| 266 | + public function cleanTube() { |
|
| 267 | 267 | $tubes = $this->queue->listTubes(); |
| 268 | - foreach ($tubes as $tube){ |
|
| 269 | - if(strpos($tube, "INBOX_") !== 0){ |
|
| 268 | + foreach ($tubes as $tube) { |
|
| 269 | + if (strpos($tube, "INBOX_") !== 0) { |
|
| 270 | 270 | continue; |
| 271 | 271 | } |
| 272 | 272 | try { |
| 273 | 273 | $statData = $this->queue->statsTube($tube)->getArrayCopy(); |
| 274 | 274 | $watching = $statData['current-watching']; |
| 275 | - if($watching !== '0'){ |
|
| 275 | + if ($watching !== '0') { |
|
| 276 | 276 | continue; |
| 277 | 277 | } |
| 278 | 278 | // Нужно удалить все Jobs. |
| 279 | 279 | $this->queue->watch($tube); |
| 280 | - while (true){ |
|
| 280 | + while (true) { |
|
| 281 | 281 | $job = $this->queue->reserveWithTimeout(1); |
| 282 | - if($job === null){ |
|
| 282 | + if ($job === null) { |
|
| 283 | 283 | break; |
| 284 | 284 | } |
| 285 | 285 | $this->queue->delete($job); |
| 286 | 286 | } |
| 287 | - }catch (\Exception $e){ |
|
| 287 | + } catch (\Exception $e) { |
|
| 288 | 288 | continue; |
| 289 | 289 | } |
| 290 | 290 | |
@@ -83,8 +83,7 @@ discard block |
||
| 83 | 83 | $job_data, |
| 84 | 84 | int $timeout = 10, |
| 85 | 85 | int $priority = PheanstalkInterface::DEFAULT_PRIORITY |
| 86 | - ) |
|
| 87 | - { |
|
| 86 | + ) { |
|
| 88 | 87 | $this->message = false; |
| 89 | 88 | $inbox_tube = uniqid('INBOX_', true); |
| 90 | 89 | $this->queue->watch($inbox_tube); |
@@ -180,7 +179,7 @@ discard block |
||
| 180 | 179 | // Processing job over callable function attached in $this->subscribe |
| 181 | 180 | if(json_decode($job->getData(), true) !==null){ |
| 182 | 181 | $mData = $job->getData(); |
| 183 | - }else{ |
|
| 182 | + } else{ |
|
| 184 | 183 | $mData = unserialize($job->getData(), [false]); |
| 185 | 184 | } |
| 186 | 185 | $this->message = $mData; |
@@ -197,8 +196,8 @@ discard block |
||
| 197 | 196 | |
| 198 | 197 | try { |
| 199 | 198 | $this->queue->delete($job); |
| 200 | - }catch (\Pheanstalk\Exception\JobNotFoundException $e){ |
|
| 201 | - }catch (\Error $e){ |
|
| 199 | + } catch (\Pheanstalk\Exception\JobNotFoundException $e){ |
|
| 200 | + } catch (\Error $e){ |
|
| 202 | 201 | } |
| 203 | 202 | } |
| 204 | 203 | |
@@ -263,7 +262,8 @@ discard block |
||
| 263 | 262 | /** |
| 264 | 263 | * Drops orphaned tasks |
| 265 | 264 | */ |
| 266 | - public function cleanTube(){ |
|
| 265 | + public function cleanTube() |
|
| 266 | + { |
|
| 267 | 267 | $tubes = $this->queue->listTubes(); |
| 268 | 268 | foreach ($tubes as $tube){ |
| 269 | 269 | if(strpos($tube, "INBOX_") !== 0){ |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | $this->queue->delete($job); |
| 286 | 286 | } |
| 287 | - }catch (\Exception $e){ |
|
| 287 | + } catch (\Exception $e){ |
|
| 288 | 288 | continue; |
| 289 | 289 | } |
| 290 | 290 | |