Completed
Pull Request — master (#93)
by Janis
07:58
created
lib/Service/RedisService.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 		$this->logger = $logger;
96 96
 		$this->l10n = $l10n;
97 97
 		$this->config = $config;
98
-		$this->redisHost = $this->config->getAppValue ( $this->appName, 'redisHost' );
99
-		$this->redisPort = intval ( $this->config->getAppValue ( $this->appName, 'redisPort' ) );
100
-		$this->redisDb = intval ( $this->config->getAppValue ( $this->appName, 'redisDb' ) );
98
+		$this->redisHost = $this->config->getAppValue($this->appName, 'redisHost');
99
+		$this->redisPort = intval($this->config->getAppValue($this->appName, 'redisPort'));
100
+		$this->redisDb = intval($this->config->getAppValue($this->appName, 'redisDb'));
101 101
 	}
102 102
 	
103 103
 	/**
@@ -110,25 +110,25 @@  discard block
 block discarded – undo
110 110
 	public function sendJob($job, $languages, $occDir) {
111 111
 		try {
112 112
 			// check for messaging and put everything together
113
-			$redis = $this->setupRedisInstance ();
113
+			$redis = $this->setupRedisInstance();
114 114
 			
115
-			$job = $this->mapper->insert ( $job );
116
-			$msg = json_encode ( array (
117
-					'id' => $job->getId (),
118
-					'type' => $job->getType (),
119
-					'source' => $job->getSource (),
120
-					'tempFile' => $job->getTempFile (),
115
+			$job = $this->mapper->insert($job);
116
+			$msg = json_encode(array(
117
+					'id' => $job->getId(),
118
+					'type' => $job->getType(),
119
+					'source' => $job->getSource(),
120
+					'tempFile' => $job->getTempFile(),
121 121
 					'languages' => $languages 
122
-			) );
123
-			if (! $redis->lPush ( OcrConstants::REDIS_NEW_JOBS_QUEUE, $msg )) {
124
-				throw new NotFoundException ( $this->l10n->t ( 'Could not add files to the redis OCR processing queue.' ) );
122
+			));
123
+			if (!$redis->lPush(OcrConstants::REDIS_NEW_JOBS_QUEUE, $msg)) {
124
+				throw new NotFoundException($this->l10n->t('Could not add files to the redis OCR processing queue.'));
125 125
 			}
126
-		} catch ( Exception $e ) {
127
-			$this->fileService->execRemove ( $job->getTempFile () );
128
-			$job->setStatus ( 'FAILED' );
129
-			$job->setErrorLog ( $this->l10n->t ( 'Could not add files to the redis OCR processing queue.' ) );
130
-			$this->mapper->update ( $job );
131
-			$this->handleException ( $e );
126
+		} catch (Exception $e) {
127
+			$this->fileService->execRemove($job->getTempFile());
128
+			$job->setStatus('FAILED');
129
+			$job->setErrorLog($this->l10n->t('Could not add files to the redis OCR processing queue.'));
130
+			$this->mapper->update($job);
131
+			$this->handleException($e);
132 132
 		}
133 133
 	}
134 134
 	
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public function readingFinishedJobs() {
141 141
 		try {
142
-			$redis = $this->setupRedisInstance ();
142
+			$redis = $this->setupRedisInstance();
143 143
 			
144
-			$result = $redis->multi ()->lRange ( OcrConstants::REDIS_FINISHED_JOBS_QUEUE, 0, - 1 )->delete ( OcrConstants::REDIS_FINISHED_JOBS_QUEUE )->exec ();
145
-			$this->logger->debug ( 'Retrieved the following array from redis: {result}', [ 
144
+			$result = $redis->multi()->lRange(OcrConstants::REDIS_FINISHED_JOBS_QUEUE, 0, - 1)->delete(OcrConstants::REDIS_FINISHED_JOBS_QUEUE)->exec();
145
+			$this->logger->debug('Retrieved the following array from redis: {result}', [ 
146 146
 					'result' => $result [0] 
147
-			] );
147
+			]);
148 148
 			return $result [0];
149
-		} catch ( Exception $e ) {
150
-			$this->handleException ( $e );
149
+		} catch (Exception $e) {
150
+			$this->handleException($e);
151 151
 		}
152 152
 	}
153 153
 	
@@ -158,21 +158,21 @@  discard block
 block discarded – undo
158 158
 	 * @return \Redis
159 159
 	 */
160 160
 	private function setupRedisInstance() {
161
-		if (! extension_loaded ( 'redis' )) {
162
-			$this->logger->debug ( 'It seems that the message queueing capabilities are not available in your local php installation. Please install php-redis.' );
163
-			throw new NotFoundException ( $this->l10n->t ( 'Message queueing capabilities are missing on the server.' ) );
161
+		if (!extension_loaded('redis')) {
162
+			$this->logger->debug('It seems that the message queueing capabilities are not available in your local php installation. Please install php-redis.');
163
+			throw new NotFoundException($this->l10n->t('Message queueing capabilities are missing on the server.'));
164 164
 		}
165 165
 		
166
-		$redis = new \Redis ();
167
-		if (! $redis->connect ( $this->redisHost, $this->redisPort, 2.5, NULL, 100 )) {
168
-			$this->logger->debug ( 'Cannot connect to Redis.' );
169
-			throw new NotFoundException ( $this->l10n->t ( 'Cannot connect to Redis.' ) );
166
+		$redis = new \Redis();
167
+		if (!$redis->connect($this->redisHost, $this->redisPort, 2.5, NULL, 100)) {
168
+			$this->logger->debug('Cannot connect to Redis.');
169
+			throw new NotFoundException($this->l10n->t('Cannot connect to Redis.'));
170 170
 		}
171
-		if (! $redis->select ( $this->redisDb )) {
172
-			$this->logger->debug ( 'Cannot connect to the right Redis database.' );
173
-			throw new NotFoundException ( $this->l10n->t ( 'Cannot connect to the right Redis database.' ) );
171
+		if (!$redis->select($this->redisDb)) {
172
+			$this->logger->debug('Cannot connect to the right Redis database.');
173
+			throw new NotFoundException($this->l10n->t('Cannot connect to the right Redis database.'));
174 174
 		}
175
-		$redis->setOption ( \Redis::OPT_PREFIX, OcrConstants::REDIS_KEY_PREFIX );
175
+		$redis->setOption(\Redis::OPT_PREFIX, OcrConstants::REDIS_KEY_PREFIX);
176 176
 		
177 177
 		return $redis;
178 178
 	}
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
 	 * @throws NotFoundException
186 186
 	 */
187 187
 	private function handleException($e) {
188
-		$this->logger->logException ( $e, [ 
188
+		$this->logger->logException($e, [ 
189 189
 				'message' => 'Exception during message queue processing' 
190
-		] );
190
+		]);
191 191
 		throw $e;
192 192
 	}
193 193
 }
194 194
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Service/StatusService.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -81,26 +81,26 @@  discard block
 block discarded – undo
81 81
 	public function getStatus() {
82 82
 		try {
83 83
 			// TODO: For now this will be placed in the regular check, but in the future this could be done in another way
84
-			$this->jobService->checkForFinishedJobs ();
84
+			$this->jobService->checkForFinishedJobs();
85 85
 			
86 86
 			// returns user specific processed files
87
-			$processed = $this->jobMapper->findAllProcessed ( $this->userId );
88
-			$this->jobService->handleProcessed ();
87
+			$processed = $this->jobMapper->findAllProcessed($this->userId);
88
+			$this->jobService->handleProcessed();
89 89
 			
90 90
 			// return user specific pending state
91
-			$pending = $this->jobMapper->findAllPending ( $this->userId );
91
+			$pending = $this->jobMapper->findAllPending($this->userId);
92 92
 			
93 93
 			// return user specific failed state and set up error
94
-			$failed = $this->jobMapper->findAllFailed ( $this->userId );
95
-			$this->jobService->handleFailed ();
94
+			$failed = $this->jobMapper->findAllFailed($this->userId);
95
+			$this->jobService->handleFailed();
96 96
 			
97 97
 			return [ 
98
-					'processed' => count ( $processed ),
99
-					'failed' => count ( $failed ),
100
-					'pending' => count ( $pending ) 
98
+					'processed' => count($processed),
99
+					'failed' => count($failed),
100
+					'pending' => count($pending) 
101 101
 			];
102
-		} catch ( Exception $e ) {
103
-			$this->handleException ( $e );
102
+		} catch (Exception $e) {
103
+			$this->handleException($e);
104 104
 		}
105 105
 	}
106 106
 	
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 * @throws NotFoundException
113 113
 	 */
114 114
 	private function handleException($e) {
115
-		$this->logger->logException ( $e, [ 
115
+		$this->logger->logException($e, [ 
116 116
 				'message' => 'Exception during status service function processing' 
117
-		] );
117
+		]);
118 118
 		throw $e;
119 119
 	}
120 120
 }
121 121
\ No newline at end of file
Please login to merge, or discard this patch.