@@ -3,7 +3,7 @@ |
||
3 | 3 | { |
4 | 4 | public function perform() |
5 | 5 | { |
6 | - fwrite(STDOUT, 'Start job! -> '); |
|
6 | + fwrite(STDOUT, 'Start job! -> '); |
|
7 | 7 | sleep(1); |
8 | 8 | fwrite(STDOUT, 'Job ended!' . PHP_EOL); |
9 | 9 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(empty($argv[1])) { |
|
2 | +if (empty($argv[1])) { |
|
3 | 3 | die('Specify the ID of a job to monitor the status of.'); |
4 | 4 | } |
5 | 5 | |
@@ -12,12 +12,12 @@ discard block |
||
12 | 12 | //Resque::setBackend('redis://user:[email protected]:3432/2'); |
13 | 13 | |
14 | 14 | $status = new Resque_Job_Status($argv[1]); |
15 | -if(!$status->isTracking()) { |
|
15 | +if (!$status->isTracking()) { |
|
16 | 16 | die("Resque is not tracking the status of this job.\n"); |
17 | 17 | } |
18 | 18 | |
19 | -echo "Tracking status of ".$argv[1].". Press [break] to stop.\n\n"; |
|
20 | -while(true) { |
|
21 | - fwrite(STDOUT, "Status of ".$argv[1]." is: ".$status->get()."\n"); |
|
19 | +echo "Tracking status of " . $argv[1] . ". Press [break] to stop.\n\n"; |
|
20 | +while (true) { |
|
21 | + fwrite(STDOUT, "Status of " . $argv[1] . " is: " . $status->get() . "\n"); |
|
22 | 22 | sleep(1); |
23 | 23 | } |
24 | 24 | \ No newline at end of file |
@@ -20,7 +20,7 @@ |
||
20 | 20 | if (empty($argv[2])) { |
21 | 21 | $jobId = Resque::enqueue('default', $argv[1], $args, true); |
22 | 22 | } else { |
23 | - $jobId = Resque::enqueue($argv[1], $argv[2], $args, true); |
|
23 | + $jobId = Resque::enqueue($argv[1], $argv[2], $args, true); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | echo "Queued job ".$jobId."\n\n"; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(empty($argv[1])) { |
|
2 | +if (empty($argv[1])) { |
|
3 | 3 | die('Specify the name of a job to add. e.g, php queue.php PHP_Job'); |
4 | 4 | } |
5 | 5 | |
@@ -23,4 +23,4 @@ discard block |
||
23 | 23 | $jobId = Resque::enqueue($argv[1], $argv[2], $args, true); |
24 | 24 | } |
25 | 25 | |
26 | -echo "Queued job ".$jobId."\n\n"; |
|
26 | +echo "Queued job " . $jobId . "\n\n"; |
@@ -227,8 +227,7 @@ |
||
227 | 227 | ); |
228 | 228 | try { |
229 | 229 | Resque_Event::trigger('beforeEnqueue', $hookParams); |
230 | - } |
|
231 | - catch(Resque_Job_DontCreate $e) { |
|
230 | + } catch(Resque_Job_DontCreate $e) { |
|
232 | 231 | return false; |
233 | 232 | } |
234 | 233 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | { |
11 | 11 | const VERSION = '1.2'; |
12 | 12 | |
13 | - const DEFAULT_INTERVAL = 5; |
|
13 | + const DEFAULT_INTERVAL = 5; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * @var Resque_Redis Instance of Resque_Redis that talks to redis. |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected static $redisDatabase = 0; |
30 | 30 | |
31 | - /** |
|
32 | - * @var string auth of Redis database |
|
33 | - */ |
|
31 | + /** |
|
32 | + * @var string auth of Redis database |
|
33 | + */ |
|
34 | 34 | protected static $auth; |
35 | 35 | |
36 | 36 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * and returns a Resque_Redis instance, or |
43 | 43 | * a nested array of servers with host/port pairs. |
44 | 44 | * @param int $database |
45 | - * @param string $auth |
|
45 | + * @param string $auth |
|
46 | 46 | */ |
47 | 47 | public static function setBackend($server, $database = 0, $auth = null) |
48 | 48 | { |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | if (!empty(self::$auth)) { |
73 | - self::$redis->auth(self::$auth); |
|
74 | - } |
|
73 | + self::$redis->auth(self::$auth); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | return self::$redis; |
77 | 77 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public static function pop($queue) |
135 | 135 | { |
136 | - $item = self::redis()->lpop('queue:' . $queue); |
|
136 | + $item = self::redis()->lpop('queue:' . $queue); |
|
137 | 137 | |
138 | 138 | if(!$item) { |
139 | 139 | return; |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public static function dequeue($queue, $items = Array()) |
153 | 153 | { |
154 | - if(count($items) > 0) { |
|
154 | + if(count($items) > 0) { |
|
155 | 155 | return self::removeItems($queue, $items); |
156 | - } else { |
|
156 | + } else { |
|
157 | 157 | return self::removeList($queue); |
158 | - } |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public static function removeQueue($queue) |
168 | 168 | { |
169 | - $num = self::removeList($queue); |
|
170 | - self::redis()->srem('queues', $queue); |
|
171 | - return $num; |
|
169 | + $num = self::removeList($queue); |
|
170 | + self::redis()->srem('queues', $queue); |
|
171 | + return $num; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -181,28 +181,28 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public static function blpop(array $queues, $timeout) |
183 | 183 | { |
184 | - $list = array(); |
|
185 | - foreach($queues AS $queue) { |
|
184 | + $list = array(); |
|
185 | + foreach($queues AS $queue) { |
|
186 | 186 | $list[] = 'queue:' . $queue; |
187 | - } |
|
187 | + } |
|
188 | 188 | |
189 | - $item = self::redis()->blpop($list, (int)$timeout); |
|
189 | + $item = self::redis()->blpop($list, (int)$timeout); |
|
190 | 190 | |
191 | - if(!$item) { |
|
191 | + if(!$item) { |
|
192 | 192 | return; |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * Normally the Resque_Redis class returns queue names without the prefix |
|
197 | - * But the blpop is a bit different. It returns the name as prefix:queue:name |
|
198 | - * So we need to strip off the prefix:queue: part |
|
199 | - */ |
|
200 | - $queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:')); |
|
195 | + /** |
|
196 | + * Normally the Resque_Redis class returns queue names without the prefix |
|
197 | + * But the blpop is a bit different. It returns the name as prefix:queue:name |
|
198 | + * So we need to strip off the prefix:queue: part |
|
199 | + */ |
|
200 | + $queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:')); |
|
201 | 201 | |
202 | - return array( |
|
202 | + return array( |
|
203 | 203 | 'queue' => $queue, |
204 | 204 | 'payload' => json_decode($item[1], true) |
205 | - ); |
|
205 | + ); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | while (!$finished) { |
331 | 331 | $string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() .$originalQueue); |
332 | 332 | if (empty($string)) { |
333 | - $finished = true; |
|
333 | + $finished = true; |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
@@ -353,29 +353,29 @@ discard block |
||
353 | 353 | */ |
354 | 354 | private static function matchItem($string, $items) |
355 | 355 | { |
356 | - $decoded = json_decode($string, true); |
|
356 | + $decoded = json_decode($string, true); |
|
357 | 357 | |
358 | - foreach($items as $key => $val) { |
|
358 | + foreach($items as $key => $val) { |
|
359 | 359 | # class name only ex: item[0] = ['class'] |
360 | 360 | if (is_numeric($key)) { |
361 | - if($decoded['class'] == $val) { |
|
361 | + if($decoded['class'] == $val) { |
|
362 | 362 | return true; |
363 | - } |
|
363 | + } |
|
364 | 364 | # class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}] |
365 | 365 | } elseif (is_array($val)) { |
366 | - $decodedArgs = (array)$decoded['args'][0]; |
|
367 | - if ($decoded['class'] == $key && |
|
366 | + $decodedArgs = (array)$decoded['args'][0]; |
|
367 | + if ($decoded['class'] == $key && |
|
368 | 368 | count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0) { |
369 | 369 | return true; |
370 | 370 | } |
371 | 371 | # class name with ID, example: item[0] = ['class' => 'id'] |
372 | 372 | } else { |
373 | - if ($decoded['class'] == $key && $decoded['id'] == $val) { |
|
373 | + if ($decoded['class'] == $key && $decoded['id'] == $val) { |
|
374 | 374 | return true; |
375 | - } |
|
375 | + } |
|
376 | 376 | } |
377 | - } |
|
378 | - return false; |
|
377 | + } |
|
378 | + return false; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
@@ -388,9 +388,9 @@ discard block |
||
388 | 388 | */ |
389 | 389 | private static function removeList($queue) |
390 | 390 | { |
391 | - $counter = self::size($queue); |
|
392 | - $result = self::redis()->del('queue:' . $queue); |
|
393 | - return ($result == 1) ? $counter : 0; |
|
391 | + $counter = self::size($queue); |
|
392 | + $result = self::redis()->del('queue:' . $queue); |
|
393 | + return ($result == 1) ? $counter : 0; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /* |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public static function fork() |
89 | 89 | { |
90 | - if(!function_exists('pcntl_fork')) { |
|
90 | + if (!function_exists('pcntl_fork')) { |
|
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | self::$redis = null; |
97 | 97 | |
98 | 98 | $pid = pcntl_fork(); |
99 | - if($pid === -1) { |
|
99 | + if ($pid === -1) { |
|
100 | 100 | throw new RuntimeException('Unable to fork child worker.'); |
101 | 101 | } |
102 | 102 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | { |
136 | 136 | $item = self::redis()->lpop('queue:' . $queue); |
137 | 137 | |
138 | - if(!$item) { |
|
138 | + if (!$item) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public static function dequeue($queue, $items = Array()) |
153 | 153 | { |
154 | - if(count($items) > 0) { |
|
154 | + if (count($items) > 0) { |
|
155 | 155 | return self::removeItems($queue, $items); |
156 | 156 | } else { |
157 | 157 | return self::removeList($queue); |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | public static function blpop(array $queues, $timeout) |
183 | 183 | { |
184 | 184 | $list = array(); |
185 | - foreach($queues AS $queue) { |
|
185 | + foreach ($queues AS $queue) { |
|
186 | 186 | $list[] = 'queue:' . $queue; |
187 | 187 | } |
188 | 188 | |
189 | 189 | $item = self::redis()->blpop($list, (int)$timeout); |
190 | 190 | |
191 | - if(!$item) { |
|
191 | + if (!$item) { |
|
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | try { |
241 | 241 | Resque_Event::trigger('beforeEnqueue', $hookParams); |
242 | 242 | } |
243 | - catch(Resque_Job_DontCreate $e) { |
|
243 | + catch (Resque_Job_DontCreate $e) { |
|
244 | 244 | return false; |
245 | 245 | } |
246 | 246 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | public static function queues() |
270 | 270 | { |
271 | 271 | $queues = self::redis()->smembers('queues'); |
272 | - if(!is_array($queues)) { |
|
272 | + if (!is_array($queues)) { |
|
273 | 273 | $queues = array(); |
274 | 274 | } |
275 | 275 | return $queues; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | public static function items($queue, $start = 0, $stop = -1) |
284 | 284 | { |
285 | 285 | $list = self::redis()->lrange('queue:' . $queue, $start, $stop); |
286 | - if(!is_array($list)) { |
|
286 | + if (!is_array($list)) { |
|
287 | 287 | $list = array(); |
288 | 288 | } |
289 | 289 | return $list; |
@@ -304,9 +304,9 @@ discard block |
||
304 | 304 | private static function removeItems($queue, $items = Array()) |
305 | 305 | { |
306 | 306 | $counter = 0; |
307 | - $originalQueue = 'queue:'. $queue; |
|
308 | - $tempQueue = $originalQueue. ':temp:'. time(); |
|
309 | - $requeueQueue = $tempQueue. ':requeue'; |
|
307 | + $originalQueue = 'queue:' . $queue; |
|
308 | + $tempQueue = $originalQueue . ':temp:' . time(); |
|
309 | + $requeueQueue = $tempQueue . ':requeue'; |
|
310 | 310 | |
311 | 311 | // move each item from original queue to temp queue and process it |
312 | 312 | $finished = false; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | $string = self::redis()->rpoplpush($originalQueue, self::redis()->getPrefix() . $tempQueue); |
315 | 315 | |
316 | 316 | if (!empty($string)) { |
317 | - if(self::matchItem($string, $items)) { |
|
317 | + if (self::matchItem($string, $items)) { |
|
318 | 318 | self::redis()->rpop($tempQueue); |
319 | 319 | $counter++; |
320 | 320 | } else { |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | // move back from temp queue to original queue |
329 | 329 | $finished = false; |
330 | 330 | while (!$finished) { |
331 | - $string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() .$originalQueue); |
|
331 | + $string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() . $originalQueue); |
|
332 | 332 | if (empty($string)) { |
333 | 333 | $finished = true; |
334 | 334 | } |
@@ -355,10 +355,10 @@ discard block |
||
355 | 355 | { |
356 | 356 | $decoded = json_decode($string, true); |
357 | 357 | |
358 | - foreach($items as $key => $val) { |
|
358 | + foreach ($items as $key => $val) { |
|
359 | 359 | # class name only ex: item[0] = ['class'] |
360 | 360 | if (is_numeric($key)) { |
361 | - if($decoded['class'] == $val) { |
|
361 | + if ($decoded['class'] == $val) { |
|
362 | 362 | return true; |
363 | 363 | } |
364 | 364 | # class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}] |
@@ -3,30 +3,30 @@ |
||
3 | 3 | class Resque_Job_Factory implements Resque_Job_FactoryInterface |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @param $className |
|
8 | - * @param array $args |
|
9 | - * @param $queue |
|
10 | - * @return Resque_JobInterface |
|
11 | - * @throws \Resque_Exception |
|
12 | - */ |
|
13 | - public function create($className, $args, $queue) |
|
14 | - { |
|
15 | - if (!class_exists($className)) { |
|
16 | - throw new Resque_Exception( |
|
17 | - 'Could not find job class ' . $className . '.' |
|
18 | - ); |
|
19 | - } |
|
6 | + /** |
|
7 | + * @param $className |
|
8 | + * @param array $args |
|
9 | + * @param $queue |
|
10 | + * @return Resque_JobInterface |
|
11 | + * @throws \Resque_Exception |
|
12 | + */ |
|
13 | + public function create($className, $args, $queue) |
|
14 | + { |
|
15 | + if (!class_exists($className)) { |
|
16 | + throw new Resque_Exception( |
|
17 | + 'Could not find job class ' . $className . '.' |
|
18 | + ); |
|
19 | + } |
|
20 | 20 | |
21 | - if (!method_exists($className, 'perform')) { |
|
22 | - throw new Resque_Exception( |
|
23 | - 'Job class ' . $className . ' does not contain a perform method.' |
|
24 | - ); |
|
25 | - } |
|
21 | + if (!method_exists($className, 'perform')) { |
|
22 | + throw new Resque_Exception( |
|
23 | + 'Job class ' . $className . ' does not contain a perform method.' |
|
24 | + ); |
|
25 | + } |
|
26 | 26 | |
27 | - $instance = new $className; |
|
28 | - $instance->args = $args; |
|
29 | - $instance->queue = $queue; |
|
30 | - return $instance; |
|
31 | - } |
|
27 | + $instance = new $className; |
|
28 | + $instance->args = $args; |
|
29 | + $instance->queue = $queue; |
|
30 | + return $instance; |
|
31 | + } |
|
32 | 32 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | $this->driver = new Credis_Client($host, $port, $timeout, $persistent); |
132 | 132 | $this->driver->setMaxConnectRetries($maxRetries); |
133 | - if ($password){ |
|
133 | + if ($password) { |
|
134 | 134 | $this->driver->auth($password); |
135 | 135 | } |
136 | 136 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $this->driver->select($database); |
146 | 146 | } |
147 | 147 | } |
148 | - catch(CredisException $e) { |
|
148 | + catch (CredisException $e) { |
|
149 | 149 | throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e); |
150 | 150 | } |
151 | 151 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | // Use a sensible default for an empty DNS string |
171 | 171 | $dsn = 'redis://' . self::DEFAULT_HOST; |
172 | 172 | } |
173 | - if(substr($dsn, 0, 7) === 'unix://') { |
|
173 | + if (substr($dsn, 0, 7) === 'unix://') { |
|
174 | 174 | return array( |
175 | 175 | $dsn, |
176 | 176 | null, |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | |
185 | 185 | // Check the URI scheme |
186 | 186 | $validSchemes = array('redis', 'tcp'); |
187 | - if (isset($parts['scheme']) && ! in_array($parts['scheme'], $validSchemes)) { |
|
187 | + if (isset($parts['scheme']) && !in_array($parts['scheme'], $validSchemes)) { |
|
188 | 188 | throw new \InvalidArgumentException("Invalid DSN. Supported schemes are " . implode(', ', $validSchemes)); |
189 | 189 | } |
190 | 190 | |
191 | 191 | // Allow simple 'hostname' format, which `parse_url` treats as a path, not host. |
192 | - if ( ! isset($parts['host']) && isset($parts['path'])) { |
|
192 | + if (!isset($parts['host']) && isset($parts['path'])) { |
|
193 | 193 | $parts['host'] = $parts['path']; |
194 | 194 | unset($parts['path']); |
195 | 195 | } |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | |
261 | 261 | public static function removePrefix($string) |
262 | 262 | { |
263 | - $prefix=self::getPrefix(); |
|
263 | + $prefix = self::getPrefix(); |
|
264 | 264 | |
265 | 265 | if (substr($string, 0, strlen($prefix)) == $prefix) { |
266 | - $string = substr($string, strlen($prefix), strlen($string) ); |
|
266 | + $string = substr($string, strlen($prefix), strlen($string)); |
|
267 | 267 | } |
268 | 268 | return $string; |
269 | 269 | } |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public static function prefix($namespace) |
100 | 100 | { |
101 | - if (substr($namespace, -1) !== ':' && $namespace != '') { |
|
102 | - $namespace .= ':'; |
|
103 | - } |
|
104 | - self::$defaultNamespace = $namespace; |
|
101 | + if (substr($namespace, -1) !== ':' && $namespace != '') { |
|
102 | + $namespace .= ':'; |
|
103 | + } |
|
104 | + self::$defaultNamespace = $namespace; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * DSN-supplied value will be used instead and this parameter is ignored. |
111 | 111 | * @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you |
112 | 112 | */ |
113 | - public function __construct($server, $database = null, $client = null) |
|
113 | + public function __construct($server, $database = null, $client = null) |
|
114 | 114 | { |
115 | 115 | try { |
116 | 116 | if (is_object($client)) { |
@@ -258,16 +258,16 @@ discard block |
||
258 | 258 | |
259 | 259 | public static function getPrefix() |
260 | 260 | { |
261 | - return self::$defaultNamespace; |
|
261 | + return self::$defaultNamespace; |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | public static function removePrefix($string) |
265 | 265 | { |
266 | - $prefix=self::getPrefix(); |
|
266 | + $prefix=self::getPrefix(); |
|
267 | 267 | |
268 | - if (substr($string, 0, strlen($prefix)) == $prefix) { |
|
269 | - $string = substr($string, strlen($prefix), strlen($string) ); |
|
270 | - } |
|
271 | - return $string; |
|
268 | + if (substr($string, 0, strlen($prefix)) == $prefix) { |
|
269 | + $string = substr($string, strlen($prefix), strlen($string) ); |
|
270 | + } |
|
271 | + return $string; |
|
272 | 272 | } |
273 | 273 | } |
@@ -115,14 +115,11 @@ discard block |
||
115 | 115 | try { |
116 | 116 | if (is_object($client)) { |
117 | 117 | $this->driver = $client; |
118 | - } |
|
119 | - elseif (is_object($server)) { |
|
118 | + } elseif (is_object($server)) { |
|
120 | 119 | $this->driver = $server; |
121 | - } |
|
122 | - elseif (is_array($server)) { |
|
120 | + } elseif (is_array($server)) { |
|
123 | 121 | $this->driver = new Credis_Cluster($server); |
124 | - } |
|
125 | - else { |
|
122 | + } else { |
|
126 | 123 | list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server); |
127 | 124 | // $user is not used, only $password |
128 | 125 | |
@@ -147,8 +144,7 @@ discard block |
||
147 | 144 | if ($database !== null) { |
148 | 145 | $this->driver->select($database); |
149 | 146 | } |
150 | - } |
|
151 | - catch(CredisException $e) { |
|
147 | + } catch(CredisException $e) { |
|
152 | 148 | throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e); |
153 | 149 | } |
154 | 150 | } |
@@ -243,15 +239,13 @@ discard block |
||
243 | 239 | foreach ($args[0] AS $i => $v) { |
244 | 240 | $args[0][$i] = self::$defaultNamespace . $v; |
245 | 241 | } |
246 | - } |
|
247 | - else { |
|
242 | + } else { |
|
248 | 243 | $args[0] = self::$defaultNamespace . $args[0]; |
249 | 244 | } |
250 | 245 | } |
251 | 246 | try { |
252 | 247 | return $this->driver->__call($name, $args); |
253 | - } |
|
254 | - catch (CredisException $e) { |
|
248 | + } catch (CredisException $e) { |
|
255 | 249 | throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e); |
256 | 250 | } |
257 | 251 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | */ |
36 | 36 | public static function getBackend() |
37 | 37 | { |
38 | - if(self::$backend === null) { |
|
38 | + if (self::$backend === null) { |
|
39 | 39 | self::$backend = 'Resque_Failure_Redis'; |
40 | 40 | } |
41 | 41 |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | private static $processPrefix = 'resque'; |
18 | 18 | |
19 | 19 | /** |
20 | - * @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface |
|
21 | - */ |
|
20 | + * @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface |
|
21 | + */ |
|
22 | 22 | public $logger; |
23 | 23 | |
24 | 24 | /** |
@@ -61,30 +61,30 @@ discard block |
||
61 | 61 | */ |
62 | 62 | private $child = null; |
63 | 63 | |
64 | - /** |
|
65 | - * Instantiate a new worker, given a list of queues that it should be working |
|
66 | - * on. The list of queues should be supplied in the priority that they should |
|
67 | - * be checked for jobs (first come, first served) |
|
68 | - * |
|
69 | - * Passing a single '*' allows the worker to work on all queues in alphabetical |
|
70 | - * order. You can easily add new queues dynamically and have them worked on using |
|
71 | - * this method. |
|
72 | - * |
|
73 | - * @param string|array $queues String with a single queue name, array with multiple. |
|
74 | - */ |
|
75 | - public function __construct($queues) |
|
76 | - { |
|
77 | - $this->logger = new Resque_Log(); |
|
64 | + /** |
|
65 | + * Instantiate a new worker, given a list of queues that it should be working |
|
66 | + * on. The list of queues should be supplied in the priority that they should |
|
67 | + * be checked for jobs (first come, first served) |
|
68 | + * |
|
69 | + * Passing a single '*' allows the worker to work on all queues in alphabetical |
|
70 | + * order. You can easily add new queues dynamically and have them worked on using |
|
71 | + * this method. |
|
72 | + * |
|
73 | + * @param string|array $queues String with a single queue name, array with multiple. |
|
74 | + */ |
|
75 | + public function __construct($queues) |
|
76 | + { |
|
77 | + $this->logger = new Resque_Log(); |
|
78 | 78 | |
79 | - if(!is_array($queues)) { |
|
80 | - $queues = array($queues); |
|
81 | - } |
|
79 | + if(!is_array($queues)) { |
|
80 | + $queues = array($queues); |
|
81 | + } |
|
82 | 82 | |
83 | - $this->queues = $queues; |
|
84 | - $this->hostname = php_uname('n'); |
|
83 | + $this->queues = $queues; |
|
84 | + $this->hostname = php_uname('n'); |
|
85 | 85 | |
86 | - $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues); |
|
87 | - } |
|
86 | + $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | /** |
90 | 90 | * Set the process prefix of the workers to the given prefix string. |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | $this->updateProcLine('Starting'); |
167 | 167 | $this->startup(); |
168 | 168 | |
169 | - if(function_exists('pcntl_signal_dispatch')) { |
|
170 | - pcntl_signal_dispatch(); |
|
171 | - } |
|
169 | + if(function_exists('pcntl_signal_dispatch')) { |
|
170 | + pcntl_signal_dispatch(); |
|
171 | + } |
|
172 | 172 | |
173 | 173 | while(true) { |
174 | 174 | if($this->shutdown) { |
@@ -177,14 +177,14 @@ discard block |
||
177 | 177 | |
178 | 178 | // is redis still alive? |
179 | 179 | try { |
180 | - if (Resque::redis()->ping() === false) { |
|
181 | - throw new CredisException('redis ping() failed'); |
|
182 | - } |
|
180 | + if (Resque::redis()->ping() === false) { |
|
181 | + throw new CredisException('redis ping() failed'); |
|
182 | + } |
|
183 | 183 | } catch (CredisException $e) { |
184 | - $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); |
|
185 | - Resque::$redis = null; |
|
186 | - usleep($interval * 1000000); |
|
187 | - continue; |
|
184 | + $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); |
|
185 | + Resque::$redis = null; |
|
186 | + usleep($interval * 1000000); |
|
187 | + continue; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // Attempt to find and reserve a job |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | // Wait until the child process finishes before continuing |
260 | 260 | while (pcntl_wait($status, WNOHANG) === 0) { |
261 | 261 | if(function_exists('pcntl_signal_dispatch')) { |
262 | - pcntl_signal_dispatch(); |
|
263 | - } |
|
262 | + pcntl_signal_dispatch(); |
|
263 | + } |
|
264 | 264 | |
265 | 265 | // Pause for a half a second to conserve system resources |
266 | 266 | usleep(500000); |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | if($blocking === true) { |
339 | - if(empty($queues)){ |
|
340 | - $this->logger->log(Psr\Log\LogLevel::INFO, 'No queue was found, sleeping for {interval}', array('interval' => $timeout)); |
|
341 | - usleep($timeout * 1000000); |
|
342 | - return false; |
|
343 | - } |
|
339 | + if(empty($queues)){ |
|
340 | + $this->logger->log(Psr\Log\LogLevel::INFO, 'No queue was found, sleeping for {interval}', array('interval' => $timeout)); |
|
341 | + usleep($timeout * 1000000); |
|
342 | + return false; |
|
343 | + } |
|
344 | 344 | $job = Resque_Job::reserveBlocking($queues, $timeout); |
345 | 345 | if($job) { |
346 | 346 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue)); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(ticks = 1); |
|
2 | +declare(ticks=1); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Resque worker that handles checking queues for jobs, fetching them |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | { |
77 | 77 | $this->logger = new Resque_Log(); |
78 | 78 | |
79 | - if(!is_array($queues)) { |
|
79 | + if (!is_array($queues)) { |
|
80 | 80 | $queues = array($queues); |
81 | 81 | } |
82 | 82 | |
83 | 83 | $this->queues = $queues; |
84 | 84 | $this->hostname = php_uname('n'); |
85 | 85 | |
86 | - $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues); |
|
86 | + $this->id = $this->hostname . ':' . getmypid() . ':' . implode(',', $this->queues); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | public static function all() |
103 | 103 | { |
104 | 104 | $workers = Resque::redis()->smembers('workers'); |
105 | - if(!is_array($workers)) { |
|
105 | + if (!is_array($workers)) { |
|
106 | 106 | $workers = array(); |
107 | 107 | } |
108 | 108 | |
109 | 109 | $instances = array(); |
110 | - foreach($workers as $workerId) { |
|
110 | + foreach ($workers as $workerId) { |
|
111 | 111 | $instances[] = self::find($workerId); |
112 | 112 | } |
113 | 113 | return $instances; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public static function find($workerId) |
134 | 134 | { |
135 | - if(!self::exists($workerId) || false === strpos($workerId, ":")) { |
|
135 | + if (!self::exists($workerId) || false === strpos($workerId, ":")) { |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
@@ -166,12 +166,12 @@ discard block |
||
166 | 166 | $this->updateProcLine('Starting'); |
167 | 167 | $this->startup(); |
168 | 168 | |
169 | - if(function_exists('pcntl_signal_dispatch')) { |
|
169 | + if (function_exists('pcntl_signal_dispatch')) { |
|
170 | 170 | pcntl_signal_dispatch(); |
171 | 171 | } |
172 | 172 | |
173 | - while(true) { |
|
174 | - if($this->shutdown) { |
|
173 | + while (true) { |
|
174 | + if ($this->shutdown) { |
|
175 | 175 | break; |
176 | 176 | } |
177 | 177 | |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | |
190 | 190 | // Attempt to find and reserve a job |
191 | 191 | $job = false; |
192 | - if(!$this->paused) { |
|
193 | - if($blocking === true) { |
|
192 | + if (!$this->paused) { |
|
193 | + if ($blocking === true) { |
|
194 | 194 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Starting blocking with timeout of {interval}', array('interval' => $interval)); |
195 | 195 | $this->updateProcLine('Waiting with blocking timeout ' . $interval); |
196 | 196 | } else { |
@@ -200,17 +200,17 @@ discard block |
||
200 | 200 | $job = $this->reserve($blocking, $interval); |
201 | 201 | } |
202 | 202 | |
203 | - if(!$job) { |
|
203 | + if (!$job) { |
|
204 | 204 | // For an interval of 0, break now - helps with unit testing etc |
205 | - if($interval == 0) { |
|
205 | + if ($interval == 0) { |
|
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - if($blocking === false) |
|
209 | + if ($blocking === false) |
|
210 | 210 | { |
211 | 211 | // If no job was found, we sleep for $interval before continuing and checking again |
212 | 212 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Sleeping for {interval}', array('interval' => $interval)); |
213 | - if($this->paused) { |
|
213 | + if ($this->paused) { |
|
214 | 214 | $this->updateProcLine('Paused'); |
215 | 215 | } |
216 | 216 | else { |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | $this->updateProcLine($status); |
236 | 236 | $this->logger->log(Psr\Log\LogLevel::INFO, $status); |
237 | 237 | |
238 | - if(!empty($job->payload['id'])) { |
|
238 | + if (!empty($job->payload['id'])) { |
|
239 | 239 | Resque_Job_PID::create($job->payload['id']); |
240 | 240 | } |
241 | 241 | |
242 | 242 | $this->perform($job); |
243 | 243 | |
244 | - if(!empty($job->payload['id'])) { |
|
244 | + if (!empty($job->payload['id'])) { |
|
245 | 245 | Resque_Job_PID::del($job->payload['id']); |
246 | 246 | } |
247 | 247 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
253 | - if($this->child > 0) { |
|
253 | + if ($this->child > 0) { |
|
254 | 254 | // Parent process, sit and wait |
255 | 255 | $status = 'Forked ' . $this->child . ' at ' . strftime('%F %T'); |
256 | 256 | $this->updateProcLine($status); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | |
259 | 259 | // Wait until the child process finishes before continuing |
260 | 260 | while (pcntl_wait($status, WNOHANG) === 0) { |
261 | - if(function_exists('pcntl_signal_dispatch')) { |
|
261 | + if (function_exists('pcntl_signal_dispatch')) { |
|
262 | 262 | pcntl_signal_dispatch(); |
263 | 263 | } |
264 | 264 | |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | Resque_Event::trigger('afterFork', $job); |
303 | 303 | $result = $job->perform(); |
304 | 304 | } |
305 | - catch(Exception $e) { |
|
305 | + catch (Exception $e) { |
|
306 | 306 | $this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {exception}', array('job' => $job, 'exception' => $e)); |
307 | 307 | $job->fail($e); |
308 | 308 | return; |
309 | 309 | } |
310 | - catch(Error $e) { |
|
310 | + catch (Error $e) { |
|
311 | 311 | $this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {exception}', array('job' => $job, 'exception' => $e)); |
312 | 312 | $job->fail($e); |
313 | 313 | return; |
@@ -331,26 +331,26 @@ discard block |
||
331 | 331 | } |
332 | 332 | |
333 | 333 | $queues = $this->queues(); |
334 | - if(!is_array($queues)) { |
|
334 | + if (!is_array($queues)) { |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | |
338 | - if($blocking === true) { |
|
339 | - if(empty($queues)){ |
|
338 | + if ($blocking === true) { |
|
339 | + if (empty($queues)) { |
|
340 | 340 | $this->logger->log(Psr\Log\LogLevel::INFO, 'No queue was found, sleeping for {interval}', array('interval' => $timeout)); |
341 | 341 | usleep($timeout * 1000000); |
342 | 342 | return false; |
343 | 343 | } |
344 | 344 | $job = Resque_Job::reserveBlocking($queues, $timeout); |
345 | - if($job) { |
|
345 | + if ($job) { |
|
346 | 346 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue)); |
347 | 347 | return $job; |
348 | 348 | } |
349 | 349 | } else { |
350 | - foreach($queues as $queue) { |
|
350 | + foreach ($queues as $queue) { |
|
351 | 351 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Checking {queue} for jobs', array('queue' => $queue)); |
352 | 352 | $job = Resque_Job::reserve($queue); |
353 | - if($job) { |
|
353 | + if ($job) { |
|
354 | 354 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue)); |
355 | 355 | return $job; |
356 | 356 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | */ |
374 | 374 | public function queues($fetch = true) |
375 | 375 | { |
376 | - if(!in_array('*', $this->queues) || $fetch == false) { |
|
376 | + if (!in_array('*', $this->queues) || $fetch == false) { |
|
377 | 377 | return $this->queues; |
378 | 378 | } |
379 | 379 | |
@@ -403,10 +403,10 @@ discard block |
||
403 | 403 | private function updateProcLine($status) |
404 | 404 | { |
405 | 405 | $processTitle = static::$processPrefix . '-' . Resque::VERSION . ' (' . implode(',', $this->queues) . '): ' . $status; |
406 | - if(function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') { |
|
406 | + if (function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') { |
|
407 | 407 | cli_set_process_title($processTitle); |
408 | 408 | } |
409 | - else if(function_exists('setproctitle')) { |
|
409 | + else if (function_exists('setproctitle')) { |
|
410 | 410 | setproctitle($processTitle); |
411 | 411 | } |
412 | 412 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | */ |
422 | 422 | private function registerSigHandlers() |
423 | 423 | { |
424 | - if(!function_exists('pcntl_signal')) { |
|
424 | + if (!function_exists('pcntl_signal')) { |
|
425 | 425 | return; |
426 | 426 | } |
427 | 427 | |
@@ -486,13 +486,13 @@ discard block |
||
486 | 486 | */ |
487 | 487 | public function killChild() |
488 | 488 | { |
489 | - if(!$this->child) { |
|
489 | + if (!$this->child) { |
|
490 | 490 | $this->logger->log(Psr\Log\LogLevel::DEBUG, 'No child to kill.'); |
491 | 491 | return; |
492 | 492 | } |
493 | 493 | |
494 | 494 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Killing child at {child}', array('child' => $this->child)); |
495 | - if(exec('ps -o pid,s -p ' . $this->child, $output, $returnCode) && $returnCode != 1) { |
|
495 | + if (exec('ps -o pid,s -p ' . $this->child, $output, $returnCode) && $returnCode != 1) { |
|
496 | 496 | $this->logger->log(Psr\Log\LogLevel::DEBUG, 'Child {child} found, killing.', array('child' => $this->child)); |
497 | 497 | posix_kill($this->child, SIGKILL); |
498 | 498 | $this->child = null; |
@@ -515,10 +515,10 @@ discard block |
||
515 | 515 | { |
516 | 516 | $workerPids = $this->workerPids(); |
517 | 517 | $workers = self::all(); |
518 | - foreach($workers as $worker) { |
|
518 | + foreach ($workers as $worker) { |
|
519 | 519 | if (is_object($worker)) { |
520 | 520 | list($host, $pid, $queues) = explode(':', (string)$worker, 3); |
521 | - if($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) { |
|
521 | + if ($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) { |
|
522 | 522 | continue; |
523 | 523 | } |
524 | 524 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Pruning dead worker: {worker}', array('worker' => (string)$worker)); |
@@ -538,14 +538,14 @@ discard block |
||
538 | 538 | $pids = array(); |
539 | 539 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
540 | 540 | exec('WMIC path win32_process get Processid,Commandline | findstr resque | findstr /V findstr', $cmdOutput); |
541 | - foreach($cmdOutput as $line) { |
|
541 | + foreach ($cmdOutput as $line) { |
|
542 | 542 | $line = preg_replace('/\s+/m', ' ', $line); |
543 | - list(,,$pids[]) = explode(' ', trim($line), 3); |
|
543 | + list(,, $pids[]) = explode(' ', trim($line), 3); |
|
544 | 544 | } |
545 | 545 | } |
546 | 546 | else { |
547 | 547 | exec('ps -A -o pid,args | grep [r]esque', $cmdOutput); |
548 | - foreach($cmdOutput as $line) { |
|
548 | + foreach ($cmdOutput as $line) { |
|
549 | 549 | list($pids[],) = explode(' ', trim($line), 2); |
550 | 550 | } |
551 | 551 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | */ |
567 | 567 | public function unregisterWorker() |
568 | 568 | { |
569 | - if(is_object($this->currentJob)) { |
|
569 | + if (is_object($this->currentJob)) { |
|
570 | 570 | $this->currentJob->fail(new Resque_Job_DirtyExitException); |
571 | 571 | } |
572 | 572 | |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | public function job() |
627 | 627 | { |
628 | 628 | $job = Resque::redis()->get('worker:' . $this); |
629 | - if(!$job) { |
|
629 | + if (!$job) { |
|
630 | 630 | return array(); |
631 | 631 | } |
632 | 632 | else { |
@@ -212,8 +212,7 @@ discard block |
||
212 | 212 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Sleeping for {interval}', array('interval' => $interval)); |
213 | 213 | if($this->paused) { |
214 | 214 | $this->updateProcLine('Paused'); |
215 | - } |
|
216 | - else { |
|
215 | + } else { |
|
217 | 216 | $this->updateProcLine('Waiting'); |
218 | 217 | } |
219 | 218 | |
@@ -272,8 +271,7 @@ discard block |
||
272 | 271 | $job->fail(new Resque_Job_DirtyExitException( |
273 | 272 | 'Job exited with exit code ' . $exitStatus |
274 | 273 | )); |
275 | - } |
|
276 | - else |
|
274 | + } else |
|
277 | 275 | { |
278 | 276 | if (in_array($job->getStatus(), array(Resque_Job_Status::STATUS_WAITING, Resque_Job_Status::STATUS_RUNNING))) |
279 | 277 | { |
@@ -301,13 +299,11 @@ discard block |
||
301 | 299 | try { |
302 | 300 | Resque_Event::trigger('afterFork', $job); |
303 | 301 | $result = $job->perform(); |
304 | - } |
|
305 | - catch(Exception $e) { |
|
302 | + } catch(Exception $e) { |
|
306 | 303 | $this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {exception}', array('job' => $job, 'exception' => $e)); |
307 | 304 | $job->fail($e); |
308 | 305 | return; |
309 | - } |
|
310 | - catch(Error $e) { |
|
306 | + } catch(Error $e) { |
|
311 | 307 | $this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {exception}', array('job' => $job, 'exception' => $e)); |
312 | 308 | $job->fail($e); |
313 | 309 | return; |
@@ -405,8 +401,7 @@ discard block |
||
405 | 401 | $processTitle = static::$processPrefix . '-' . Resque::VERSION . ' (' . implode(',', $this->queues) . '): ' . $status; |
406 | 402 | if(function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') { |
407 | 403 | cli_set_process_title($processTitle); |
408 | - } |
|
409 | - else if(function_exists('setproctitle')) { |
|
404 | + } else if(function_exists('setproctitle')) { |
|
410 | 405 | setproctitle($processTitle); |
411 | 406 | } |
412 | 407 | } |
@@ -496,8 +491,7 @@ discard block |
||
496 | 491 | $this->logger->log(Psr\Log\LogLevel::DEBUG, 'Child {child} found, killing.', array('child' => $this->child)); |
497 | 492 | posix_kill($this->child, SIGKILL); |
498 | 493 | $this->child = null; |
499 | - } |
|
500 | - else { |
|
494 | + } else { |
|
501 | 495 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Child {child} not found, restarting.', array('child' => $this->child)); |
502 | 496 | $this->shutdown(); |
503 | 497 | } |
@@ -542,8 +536,7 @@ discard block |
||
542 | 536 | $line = preg_replace('/\s+/m', ' ', $line); |
543 | 537 | list(,,$pids[]) = explode(' ', trim($line), 3); |
544 | 538 | } |
545 | - } |
|
546 | - else { |
|
539 | + } else { |
|
547 | 540 | exec('ps -A -o pid,args | grep [r]esque', $cmdOutput); |
548 | 541 | foreach($cmdOutput as $line) { |
549 | 542 | list($pids[],) = explode(' ', trim($line), 2); |
@@ -628,8 +621,7 @@ discard block |
||
628 | 621 | $job = Resque::redis()->get('worker:' . $this); |
629 | 622 | if(!$job) { |
630 | 623 | return array(); |
631 | - } |
|
632 | - else { |
|
624 | + } else { |
|
633 | 625 | return json_decode($job, true); |
634 | 626 | } |
635 | 627 | } |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | const STATUS_COMPLETE = 4; |
15 | 15 | |
16 | 16 | /** |
17 | - * @var string The prefix of the job status id. |
|
18 | - */ |
|
17 | + * @var string The prefix of the job status id. |
|
18 | + */ |
|
19 | 19 | private $prefix; |
20 | 20 | |
21 | 21 | /** |
@@ -143,33 +143,33 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | - * Fetch the last update timestamp of the job being monitored. |
|
147 | - * |
|
148 | - * @return mixed False if the job is not being monitored, otherwise the |
|
146 | + * Fetch the last update timestamp of the job being monitored. |
|
147 | + * |
|
148 | + * @return mixed False if the job is not being monitored, otherwise the |
|
149 | 149 | * update timestamp. |
150 | - */ |
|
150 | + */ |
|
151 | 151 | public function updated() |
152 | 152 | { |
153 | 153 | return $this->fetch('updated'); |
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | - * Fetch the start timestamp of the job being monitored. |
|
158 | - * |
|
159 | - * @return mixed False if the job is not being monitored, otherwise the |
|
157 | + * Fetch the start timestamp of the job being monitored. |
|
158 | + * |
|
159 | + * @return mixed False if the job is not being monitored, otherwise the |
|
160 | 160 | * start timestamp. |
161 | - */ |
|
161 | + */ |
|
162 | 162 | public function started() |
163 | 163 | { |
164 | 164 | return $this->fetch('started'); |
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | - * Fetch the result of the job being monitored. |
|
169 | - * |
|
170 | - * @return mixed False if the job is not being monitored, otherwise the result |
|
171 | - * as mixed |
|
172 | - */ |
|
168 | + * Fetch the result of the job being monitored. |
|
169 | + * |
|
170 | + * @return mixed False if the job is not being monitored, otherwise the result |
|
171 | + * as mixed |
|
172 | + */ |
|
173 | 173 | public function result() |
174 | 174 | { |
175 | 175 | return $this->fetch('result'); |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | - * Fetch a value from the status packet for the job being monitored. |
|
198 | - * |
|
199 | - * @return mixed False if the status is not being monitored, otherwise the |
|
200 | - * requested value from the status packet. |
|
201 | - */ |
|
197 | + * Fetch a value from the status packet for the job being monitored. |
|
198 | + * |
|
199 | + * @return mixed False if the status is not being monitored, otherwise the |
|
200 | + * requested value from the status packet. |
|
201 | + */ |
|
202 | 202 | protected function fetch($value = null) |
203 | 203 | { |
204 | 204 | if(!$this->isTracking()) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | 'started' => time(), |
64 | 64 | 'result' => null, |
65 | 65 | ); |
66 | - Resque::redis()->set((string) $status, json_encode($statusPacket)); |
|
66 | + Resque::redis()->set((string)$status, json_encode($statusPacket)); |
|
67 | 67 | |
68 | 68 | return $status; |
69 | 69 | } |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function isTracking() |
78 | 78 | { |
79 | - if($this->isTracking === false) { |
|
79 | + if ($this->isTracking === false) { |
|
80 | 80 | return false; |
81 | 81 | } |
82 | 82 | |
83 | - if(!Resque::redis()->exists((string)$this)) { |
|
83 | + if (!Resque::redis()->exists((string)$this)) { |
|
84 | 84 | $this->isTracking = false; |
85 | 85 | return false; |
86 | 86 | } |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function update($status, $result = null) |
98 | 98 | { |
99 | - $status = (int) $status; |
|
99 | + $status = (int)$status; |
|
100 | 100 | |
101 | - if(!$this->isTracking()) { |
|
101 | + if (!$this->isTracking()) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | - if($status < self::STATUS_WAITING || $status > self::STATUS_COMPLETE) { |
|
105 | + if ($status < self::STATUS_WAITING || $status > self::STATUS_COMPLETE) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | Resque::redis()->set((string)$this, json_encode($statusPacket)); |
116 | 116 | |
117 | 117 | // Expire the status for completed jobs after 24 hours |
118 | - if(in_array($status, self::$completeStatuses)) { |
|
118 | + if (in_array($status, self::$completeStatuses)) { |
|
119 | 119 | Resque::redis()->expire((string)$this, 86400); |
120 | 120 | } |
121 | 121 | } |
@@ -201,19 +201,19 @@ discard block |
||
201 | 201 | */ |
202 | 202 | protected function fetch($value = null) |
203 | 203 | { |
204 | - if(!$this->isTracking()) { |
|
204 | + if (!$this->isTracking()) { |
|
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
208 | 208 | $statusPacket = json_decode(Resque::redis()->get((string)$this), true); |
209 | - if(!$statusPacket) { |
|
209 | + if (!$statusPacket) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | - if(empty($value)) { |
|
213 | + if (empty($value)) { |
|
214 | 214 | return $statusPacket; |
215 | 215 | } else { |
216 | - if(isset($statusPacket[$value])) { |
|
216 | + if (isset($statusPacket[$value])) { |
|
217 | 217 | return $statusPacket[$value]; |
218 | 218 | } else { |
219 | 219 | return null; |