@@ -75,24 +75,24 @@ discard block |
||
75 | 75 | public function sendJob($job, $languages, $occDir) { |
76 | 76 | try { |
77 | 77 | // check for messaging and put everything together |
78 | - $redis = $this->setupRedisInstance (); |
|
78 | + $redis = $this->setupRedisInstance(); |
|
79 | 79 | |
80 | - $job = $this->mapper->insert ( $job ); |
|
81 | - $msg = json_encode ( array ( |
|
82 | - 'id' => $job->getId (), |
|
83 | - 'type' => $job->getType (), |
|
84 | - 'source' => $job->getSource (), |
|
85 | - 'tempFile' => $job->getTempFile (), |
|
80 | + $job = $this->mapper->insert($job); |
|
81 | + $msg = json_encode(array( |
|
82 | + 'id' => $job->getId(), |
|
83 | + 'type' => $job->getType(), |
|
84 | + 'source' => $job->getSource(), |
|
85 | + 'tempFile' => $job->getTempFile(), |
|
86 | 86 | 'languages' => $languages |
87 | - ) ); |
|
88 | - if (! $redis->lPush ( 'incoming', $msg )) { |
|
89 | - throw new NotFoundException ( $this->l10n->t ( 'Could not add files to the redis OCR processing queue.' ) ); |
|
87 | + )); |
|
88 | + if (!$redis->lPush('incoming', $msg)) { |
|
89 | + throw new NotFoundException($this->l10n->t('Could not add files to the redis OCR processing queue.')); |
|
90 | 90 | } |
91 | - } catch ( Exception $e ) { |
|
92 | - exec ( 'rm ' . $job->getTempFile () ); |
|
93 | - $job->setStatus ( 'FAILED' ); |
|
94 | - $this->mapper->update ( $job ); |
|
95 | - $this->handleException ( $e ); |
|
91 | + } catch (Exception $e) { |
|
92 | + exec('rm ' . $job->getTempFile()); |
|
93 | + $job->setStatus('FAILED'); |
|
94 | + $this->mapper->update($job); |
|
95 | + $this->handleException($e); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -105,28 +105,28 @@ discard block |
||
105 | 105 | * @return \Redis |
106 | 106 | */ |
107 | 107 | private function setupRedisInstance() { |
108 | - if (! extension_loaded ( 'redis' )) { |
|
109 | - $this->logger->debug ( 'It seems that the message queueing capabilities are not available in your local php installation. Please install php-redis.', [ |
|
108 | + if (!extension_loaded('redis')) { |
|
109 | + $this->logger->debug('It seems that the message queueing capabilities are not available in your local php installation. Please install php-redis.', [ |
|
110 | 110 | 'app' => 'ocr' |
111 | - ] ); |
|
112 | - throw new NotFoundException ( $this->l10n->t ( 'Message queueing capabilities are missing on the server.' ) ); |
|
111 | + ]); |
|
112 | + throw new NotFoundException($this->l10n->t('Message queueing capabilities are missing on the server.')); |
|
113 | 113 | } |
114 | 114 | |
115 | - $redis = new \Redis (); |
|
115 | + $redis = new \Redis(); |
|
116 | 116 | // TODO: get from config |
117 | - if (! $redis->connect ( '127.0.0.1', 6379, 2.5, NULL, 100 )) { |
|
118 | - $this->logger->debug ( 'Cannot connect to Redis.', [ |
|
117 | + if (!$redis->connect('127.0.0.1', 6379, 2.5, NULL, 100)) { |
|
118 | + $this->logger->debug('Cannot connect to Redis.', [ |
|
119 | 119 | 'app' => 'ocr' |
120 | - ] ); |
|
121 | - throw new NotFoundException ( $this->l10n->t ( 'Cannot connect to Redis.' ) ); |
|
120 | + ]); |
|
121 | + throw new NotFoundException($this->l10n->t('Cannot connect to Redis.')); |
|
122 | 122 | } |
123 | - if (! $redis->select ( 0 )) { |
|
124 | - $this->logger->debug ( 'Cannot connect to the right Redis database.', [ |
|
123 | + if (!$redis->select(0)) { |
|
124 | + $this->logger->debug('Cannot connect to the right Redis database.', [ |
|
125 | 125 | 'app' => 'ocr' |
126 | - ] ); |
|
127 | - throw new NotFoundException ( $this->l10n->t ( 'Cannot connect to the right Redis database.' ) ); |
|
126 | + ]); |
|
127 | + throw new NotFoundException($this->l10n->t('Cannot connect to the right Redis database.')); |
|
128 | 128 | } |
129 | - $redis->setOption ( \Redis::OPT_PREFIX, 'ocr:' ); |
|
129 | + $redis->setOption(\Redis::OPT_PREFIX, 'ocr:'); |
|
130 | 130 | |
131 | 131 | return $redis; |
132 | 132 | } |
@@ -139,12 +139,12 @@ discard block |
||
139 | 139 | * @throws NotFoundException |
140 | 140 | */ |
141 | 141 | private function handleException($e) { |
142 | - $this->logger->logException ( $e, [ |
|
142 | + $this->logger->logException($e, [ |
|
143 | 143 | 'app' => 'ocr', |
144 | 144 | 'message' => 'Exception during message queue processing' |
145 | - ] ); |
|
145 | + ]); |
|
146 | 146 | if ($e instanceof NotFoundException) { |
147 | - throw new NotFoundException ( $e->getMessage () ); |
|
147 | + throw new NotFoundException($e->getMessage()); |
|
148 | 148 | } else { |
149 | 149 | throw $e; |
150 | 150 | } |