@@ -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 | } |
@@ -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"; |
@@ -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. |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public static function pop($queue) |
124 | 124 | { |
125 | - $item = self::redis()->lpop('queue:' . $queue); |
|
125 | + $item = self::redis()->lpop('queue:' . $queue); |
|
126 | 126 | |
127 | 127 | if(!$item) { |
128 | 128 | return; |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public static function dequeue($queue, $items = Array()) |
142 | 142 | { |
143 | - if(count($items) > 0) { |
|
143 | + if(count($items) > 0) { |
|
144 | 144 | return self::removeItems($queue, $items); |
145 | - } else { |
|
145 | + } else { |
|
146 | 146 | return self::removeList($queue); |
147 | - } |
|
147 | + } |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public static function removeQueue($queue) |
157 | 157 | { |
158 | - $num = self::removeList($queue); |
|
159 | - self::redis()->srem('queues', $queue); |
|
160 | - return $num; |
|
158 | + $num = self::removeList($queue); |
|
159 | + self::redis()->srem('queues', $queue); |
|
160 | + return $num; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -170,28 +170,28 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public static function blpop(array $queues, $timeout) |
172 | 172 | { |
173 | - $list = array(); |
|
174 | - foreach($queues AS $queue) { |
|
173 | + $list = array(); |
|
174 | + foreach($queues AS $queue) { |
|
175 | 175 | $list[] = 'queue:' . $queue; |
176 | - } |
|
176 | + } |
|
177 | 177 | |
178 | - $item = self::redis()->blpop($list, (int)$timeout); |
|
178 | + $item = self::redis()->blpop($list, (int)$timeout); |
|
179 | 179 | |
180 | - if(!$item) { |
|
180 | + if(!$item) { |
|
181 | 181 | return; |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Normally the Resque_Redis class returns queue names without the prefix |
|
186 | - * But the blpop is a bit different. It returns the name as prefix:queue:name |
|
187 | - * So we need to strip off the prefix:queue: part |
|
188 | - */ |
|
189 | - $queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:')); |
|
184 | + /** |
|
185 | + * Normally the Resque_Redis class returns queue names without the prefix |
|
186 | + * But the blpop is a bit different. It returns the name as prefix:queue:name |
|
187 | + * So we need to strip off the prefix:queue: part |
|
188 | + */ |
|
189 | + $queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:')); |
|
190 | 190 | |
191 | - return array( |
|
191 | + return array( |
|
192 | 192 | 'queue' => $queue, |
193 | 193 | 'payload' => json_decode($item[1], true) |
194 | - ); |
|
194 | + ); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | while (!$finished) { |
305 | 305 | $string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() .$originalQueue); |
306 | 306 | if (empty($string)) { |
307 | - $finished = true; |
|
307 | + $finished = true; |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
@@ -327,29 +327,29 @@ discard block |
||
327 | 327 | */ |
328 | 328 | private static function matchItem($string, $items) |
329 | 329 | { |
330 | - $decoded = json_decode($string, true); |
|
330 | + $decoded = json_decode($string, true); |
|
331 | 331 | |
332 | - foreach($items as $key => $val) { |
|
332 | + foreach($items as $key => $val) { |
|
333 | 333 | # class name only ex: item[0] = ['class'] |
334 | 334 | if (is_numeric($key)) { |
335 | - if($decoded['class'] == $val) { |
|
335 | + if($decoded['class'] == $val) { |
|
336 | 336 | return true; |
337 | - } |
|
337 | + } |
|
338 | 338 | # class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}] |
339 | - } elseif (is_array($val)) { |
|
340 | - $decodedArgs = (array)$decoded['args'][0]; |
|
341 | - if ($decoded['class'] == $key && |
|
339 | + } elseif (is_array($val)) { |
|
340 | + $decodedArgs = (array)$decoded['args'][0]; |
|
341 | + if ($decoded['class'] == $key && |
|
342 | 342 | count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0) { |
343 | 343 | return true; |
344 | 344 | } |
345 | 345 | # class name with ID, example: item[0] = ['class' => 'id'] |
346 | 346 | } else { |
347 | - if ($decoded['class'] == $key && $decoded['id'] == $val) { |
|
347 | + if ($decoded['class'] == $key && $decoded['id'] == $val) { |
|
348 | 348 | return true; |
349 | - } |
|
349 | + } |
|
350 | + } |
|
350 | 351 | } |
351 | - } |
|
352 | - return false; |
|
352 | + return false; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | /** |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | */ |
363 | 363 | private static function removeList($queue) |
364 | 364 | { |
365 | - $counter = self::size($queue); |
|
366 | - $result = self::redis()->del('queue:' . $queue); |
|
367 | - return ($result == 1) ? $counter : 0; |
|
365 | + $counter = self::size($queue); |
|
366 | + $result = self::redis()->del('queue:' . $queue); |
|
367 | + return ($result == 1) ? $counter : 0; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /* |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | return $this->instance; |
170 | 170 | } |
171 | 171 | |
172 | - $this->instance = $this->getJobFactory()->create($this->payload['class'], $this->getArguments(), $this->queue); |
|
173 | - $this->instance->job = $this; |
|
174 | - return $this->instance; |
|
172 | + $this->instance = $this->getJobFactory()->create($this->payload['class'], $this->getArguments(), $this->queue); |
|
173 | + $this->instance->job = $this; |
|
174 | + return $this->instance; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -276,14 +276,14 @@ discard block |
||
276 | 276 | return $this; |
277 | 277 | } |
278 | 278 | |
279 | - /** |
|
280 | - * @return Resque_Job_FactoryInterface |
|
281 | - */ |
|
282 | - public function getJobFactory() |
|
283 | - { |
|
284 | - if ($this->jobFactory === null) { |
|
285 | - $this->jobFactory = new Resque_Job_Factory(); |
|
286 | - } |
|
287 | - return $this->jobFactory; |
|
288 | - } |
|
279 | + /** |
|
280 | + * @return Resque_Job_FactoryInterface |
|
281 | + */ |
|
282 | + public function getJobFactory() |
|
283 | + { |
|
284 | + if ($this->jobFactory === null) { |
|
285 | + $this->jobFactory = new Resque_Job_Factory(); |
|
286 | + } |
|
287 | + return $this->jobFactory; |
|
288 | + } |
|
289 | 289 | } |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | class Resque_Worker |
13 | 13 | { |
14 | 14 | /** |
15 | - * @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface |
|
16 | - */ |
|
15 | + * @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface |
|
16 | + */ |
|
17 | 17 | public $logger; |
18 | 18 | |
19 | 19 | /** |
@@ -56,30 +56,30 @@ discard block |
||
56 | 56 | */ |
57 | 57 | private $child = null; |
58 | 58 | |
59 | - /** |
|
60 | - * Instantiate a new worker, given a list of queues that it should be working |
|
61 | - * on. The list of queues should be supplied in the priority that they should |
|
62 | - * be checked for jobs (first come, first served) |
|
63 | - * |
|
64 | - * Passing a single '*' allows the worker to work on all queues in alphabetical |
|
65 | - * order. You can easily add new queues dynamically and have them worked on using |
|
66 | - * this method. |
|
67 | - * |
|
68 | - * @param string|array $queues String with a single queue name, array with multiple. |
|
69 | - */ |
|
70 | - public function __construct($queues) |
|
71 | - { |
|
72 | - $this->logger = new Resque_Log(); |
|
73 | - |
|
74 | - if(!is_array($queues)) { |
|
75 | - $queues = array($queues); |
|
76 | - } |
|
77 | - |
|
78 | - $this->queues = $queues; |
|
79 | - $this->hostname = php_uname('n'); |
|
80 | - |
|
81 | - $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues); |
|
82 | - } |
|
59 | + /** |
|
60 | + * Instantiate a new worker, given a list of queues that it should be working |
|
61 | + * on. The list of queues should be supplied in the priority that they should |
|
62 | + * be checked for jobs (first come, first served) |
|
63 | + * |
|
64 | + * Passing a single '*' allows the worker to work on all queues in alphabetical |
|
65 | + * order. You can easily add new queues dynamically and have them worked on using |
|
66 | + * this method. |
|
67 | + * |
|
68 | + * @param string|array $queues String with a single queue name, array with multiple. |
|
69 | + */ |
|
70 | + public function __construct($queues) |
|
71 | + { |
|
72 | + $this->logger = new Resque_Log(); |
|
73 | + |
|
74 | + if(!is_array($queues)) { |
|
75 | + $queues = array($queues); |
|
76 | + } |
|
77 | + |
|
78 | + $this->queues = $queues; |
|
79 | + $this->hostname = php_uname('n'); |
|
80 | + |
|
81 | + $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues); |
|
82 | + } |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Return all workers known to Resque as instantiated instances. |
@@ -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 | } |
@@ -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_array($server)) { |
@@ -255,16 +255,16 @@ discard block |
||
255 | 255 | |
256 | 256 | public static function getPrefix() |
257 | 257 | { |
258 | - return self::$defaultNamespace; |
|
258 | + return self::$defaultNamespace; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | public static function removePrefix($string) |
262 | 262 | { |
263 | - $prefix=self::getPrefix(); |
|
263 | + $prefix=self::getPrefix(); |
|
264 | 264 | |
265 | - if (substr($string, 0, strlen($prefix)) == $prefix) { |
|
266 | - $string = substr($string, strlen($prefix), strlen($string) ); |
|
267 | - } |
|
268 | - return $string; |
|
265 | + if (substr($string, 0, strlen($prefix)) == $prefix) { |
|
266 | + $string = substr($string, strlen($prefix), strlen($string) ); |
|
267 | + } |
|
268 | + return $string; |
|
269 | 269 | } |
270 | 270 | } |