@@ -91,59 +91,59 @@ |
||
91 | 91 | return Resque::redis()->llen('delayed:' . $timestamp, $timestamp); |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * Remove a delayed job from the queue |
|
96 | - * |
|
97 | - * note: you must specify exactly the same |
|
98 | - * queue, class and arguments that you used when you added |
|
99 | - * to the delayed queue |
|
100 | - * |
|
101 | - * also, this is an expensive operation because all delayed keys have tobe |
|
102 | - * searched |
|
103 | - * |
|
104 | - * @param $queue |
|
105 | - * @param $class |
|
106 | - * @param $args |
|
107 | - * @return int number of jobs that were removed |
|
108 | - */ |
|
109 | - public static function removeDelayed($queue, $class, $args) |
|
110 | - { |
|
111 | - $destroyed=0; |
|
112 | - $item=json_encode(self::jobToHash($queue, $class, $args)); |
|
113 | - $redis=Resque::redis(); |
|
94 | + /** |
|
95 | + * Remove a delayed job from the queue |
|
96 | + * |
|
97 | + * note: you must specify exactly the same |
|
98 | + * queue, class and arguments that you used when you added |
|
99 | + * to the delayed queue |
|
100 | + * |
|
101 | + * also, this is an expensive operation because all delayed keys have tobe |
|
102 | + * searched |
|
103 | + * |
|
104 | + * @param $queue |
|
105 | + * @param $class |
|
106 | + * @param $args |
|
107 | + * @return int number of jobs that were removed |
|
108 | + */ |
|
109 | + public static function removeDelayed($queue, $class, $args) |
|
110 | + { |
|
111 | + $destroyed=0; |
|
112 | + $item=json_encode(self::jobToHash($queue, $class, $args)); |
|
113 | + $redis=Resque::redis(); |
|
114 | 114 | |
115 | - foreach($redis->keys('delayed:*') as $key) |
|
116 | - { |
|
117 | - $key=$redis->removePrefix($key); |
|
118 | - $destroyed+=$redis->lrem($key,0,$item); |
|
119 | - } |
|
115 | + foreach($redis->keys('delayed:*') as $key) |
|
116 | + { |
|
117 | + $key=$redis->removePrefix($key); |
|
118 | + $destroyed+=$redis->lrem($key,0,$item); |
|
119 | + } |
|
120 | 120 | |
121 | - return $destroyed; |
|
122 | - } |
|
121 | + return $destroyed; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * removed a delayed job queued for a specific timestamp |
|
126 | - * |
|
127 | - * note: you must specify exactly the same |
|
128 | - * queue, class and arguments that you used when you added |
|
129 | - * to the delayed queue |
|
130 | - * |
|
131 | - * @param $timestamp |
|
132 | - * @param $queue |
|
133 | - * @param $class |
|
134 | - * @param $args |
|
135 | - * @return mixed |
|
136 | - */ |
|
137 | - public static function removeDelayedJobFromTimestamp($timestamp, $queue, $class, $args) |
|
138 | - { |
|
139 | - $key = 'delayed:' . self::getTimestamp($timestamp); |
|
140 | - $item = json_encode(self::jobToHash($queue, $class, $args)); |
|
141 | - $redis = Resque::redis(); |
|
142 | - $count = $redis->lrem($key, 0, $item); |
|
143 | - self::cleanupTimestamp($key, $timestamp); |
|
124 | + /** |
|
125 | + * removed a delayed job queued for a specific timestamp |
|
126 | + * |
|
127 | + * note: you must specify exactly the same |
|
128 | + * queue, class and arguments that you used when you added |
|
129 | + * to the delayed queue |
|
130 | + * |
|
131 | + * @param $timestamp |
|
132 | + * @param $queue |
|
133 | + * @param $class |
|
134 | + * @param $args |
|
135 | + * @return mixed |
|
136 | + */ |
|
137 | + public static function removeDelayedJobFromTimestamp($timestamp, $queue, $class, $args) |
|
138 | + { |
|
139 | + $key = 'delayed:' . self::getTimestamp($timestamp); |
|
140 | + $item = json_encode(self::jobToHash($queue, $class, $args)); |
|
141 | + $redis = Resque::redis(); |
|
142 | + $count = $redis->lrem($key, 0, $item); |
|
143 | + self::cleanupTimestamp($key, $timestamp); |
|
144 | 144 | |
145 | - return $count; |
|
146 | - } |
|
145 | + return $count; |
|
146 | + } |
|
147 | 147 | |
148 | 148 | /** |
149 | 149 | * Generate hash of all job properties to be saved in the scheduled queue. |
@@ -108,14 +108,14 @@ |
||
108 | 108 | */ |
109 | 109 | public static function removeDelayed($queue, $class, $args) |
110 | 110 | { |
111 | - $destroyed=0; |
|
112 | - $item=json_encode(self::jobToHash($queue, $class, $args)); |
|
113 | - $redis=Resque::redis(); |
|
111 | + $destroyed = 0; |
|
112 | + $item = json_encode(self::jobToHash($queue, $class, $args)); |
|
113 | + $redis = Resque::redis(); |
|
114 | 114 | |
115 | - foreach($redis->keys('delayed:*') as $key) |
|
115 | + foreach ($redis->keys('delayed:*') as $key) |
|
116 | 116 | { |
117 | - $key=$redis->removePrefix($key); |
|
118 | - $destroyed+=$redis->lrem($key,0,$item); |
|
117 | + $key = $redis->removePrefix($key); |
|
118 | + $destroyed += $redis->lrem($key, 0, $item); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | return $destroyed; |
@@ -220,8 +220,7 @@ discard block |
||
220 | 220 | { |
221 | 221 | if ($at === null) { |
222 | 222 | $at = time(); |
223 | - } |
|
224 | - else { |
|
223 | + } else { |
|
225 | 224 | $at = self::getTimestamp($at); |
226 | 225 | } |
227 | 226 | |
@@ -261,8 +260,7 @@ discard block |
||
261 | 260 | { |
262 | 261 | if (empty($class)) { |
263 | 262 | throw new Resque_Exception('Jobs must be given a class.'); |
264 | - } |
|
265 | - else if (empty($queue)) { |
|
263 | + } else if (empty($queue)) { |
|
266 | 264 | throw new Resque_Exception('Jobs must be put in a queue.'); |
267 | 265 | } |
268 | 266 |
@@ -119,8 +119,7 @@ |
||
119 | 119 | { |
120 | 120 | if($this->logLevel == self::LOG_NORMAL) { |
121 | 121 | fwrite(STDOUT, "*** " . $message . "\n"); |
122 | - } |
|
123 | - else if($this->logLevel == self::LOG_VERBOSE) { |
|
122 | + } else if($this->logLevel == self::LOG_VERBOSE) { |
|
124 | 123 | fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n"); |
125 | 124 | } |
126 | 125 | } |
@@ -36,13 +36,13 @@ |
||
36 | 36 | private $paused = false; |
37 | 37 | |
38 | 38 | /** |
39 | - * The primary loop for a worker. |
|
40 | - * |
|
41 | - * Every $interval (seconds), the scheduled queue will be checked for jobs |
|
42 | - * that should be pushed to Resque. |
|
43 | - * |
|
44 | - * @param int $interval How often to check schedules. |
|
45 | - */ |
|
39 | + * The primary loop for a worker. |
|
40 | + * |
|
41 | + * Every $interval (seconds), the scheduled queue will be checked for jobs |
|
42 | + * that should be pushed to Resque. |
|
43 | + * |
|
44 | + * @param int $interval How often to check schedules. |
|
45 | + */ |
|
46 | 46 | public function work($interval = null) |
47 | 47 | { |
48 | 48 | if ($interval !== null) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(ticks = 1); |
|
2 | +declare(ticks=1); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * ResqueScheduler worker to handle scheduling of delayed tasks. |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | $this->registerSigHandlers(); |
54 | 54 | |
55 | 55 | while (true) { |
56 | - if($this->shutdown) { |
|
56 | + if ($this->shutdown) { |
|
57 | 57 | break; |
58 | 58 | } |
59 | - if(!$this->paused) { |
|
59 | + if (!$this->paused) { |
|
60 | 60 | $this->handleDelayedItems(); |
61 | 61 | } |
62 | 62 | $this->sleep(); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | { |
92 | 92 | $item = null; |
93 | 93 | while ($item = ResqueScheduler::nextItemForTimestamp($timestamp)) { |
94 | - $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] .' [delayed]'); |
|
94 | + $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] . ' [delayed]'); |
|
95 | 95 | |
96 | 96 | Resque_Event::trigger('beforeDelayedEnqueue', array( |
97 | 97 | 'queue' => $item['queue'], |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | private function updateProcLine($status) |
125 | 125 | { |
126 | - if(function_exists('setproctitle')) { |
|
126 | + if (function_exists('setproctitle')) { |
|
127 | 127 | setproctitle('resque-scheduler-' . ResqueScheduler::VERSION . ': ' . $status); |
128 | 128 | } |
129 | 129 | } |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function log($message) |
137 | 137 | { |
138 | - if($this->logLevel == self::LOG_NORMAL) { |
|
138 | + if ($this->logLevel == self::LOG_NORMAL) { |
|
139 | 139 | fwrite(STDOUT, "*** " . $message . "\n"); |
140 | 140 | } |
141 | - else if($this->logLevel == self::LOG_VERBOSE) { |
|
141 | + else if ($this->logLevel == self::LOG_VERBOSE) { |
|
142 | 142 | fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n"); |
143 | 143 | } |
144 | 144 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | private function registerSigHandlers() |
154 | 154 | { |
155 | - if(!function_exists('pcntl_signal')) { |
|
155 | + if (!function_exists('pcntl_signal')) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $id = Resque::generateJobId(); |
65 | 65 | } |
66 | 66 | |
67 | - if($args !== null && !is_array($args)) { |
|
67 | + if ($args !== null && !is_array($args)) { |
|
68 | 68 | throw new InvalidArgumentException( |
69 | 69 | 'Supplied $args must be an array.' |
70 | 70 | ); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'queue_time' => microtime(true), |
78 | 78 | )); |
79 | 79 | |
80 | - if($monitor) { |
|
80 | + if ($monitor) { |
|
81 | 81 | Resque_Job_Status::create($id, $prefix); |
82 | 82 | } |
83 | 83 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | public static function reserve($queue) |
95 | 95 | { |
96 | 96 | $payload = Resque::pop($queue); |
97 | - if(!is_array($payload)) { |
|
97 | + if (!is_array($payload)) { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | { |
114 | 114 | $item = Resque::blpop($queues, $timeout); |
115 | 115 | |
116 | - if(!is_array($item)) { |
|
116 | + if (!is_array($item)) { |
|
117 | 117 | return false; |
118 | 118 | } |
119 | 119 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function updateStatus($status, $result = null) |
129 | 129 | { |
130 | - if(empty($this->payload['id'])) { |
|
130 | + if (empty($this->payload['id'])) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function getStatus() |
144 | 144 | { |
145 | - if(empty($this->payload['id'])) { |
|
145 | + if (empty($this->payload['id'])) { |
|
146 | 146 | return null; |
147 | 147 | } |
148 | 148 | |
@@ -194,20 +194,20 @@ discard block |
||
194 | 194 | Resque_Event::trigger('beforePerform', $this); |
195 | 195 | |
196 | 196 | $instance = $this->getInstance(); |
197 | - if(is_callable([$instance, 'setUp'])) { |
|
197 | + if (is_callable([$instance, 'setUp'])) { |
|
198 | 198 | $instance->setUp(); |
199 | 199 | } |
200 | 200 | |
201 | 201 | $result = $instance->perform(); |
202 | 202 | |
203 | - if(is_callable([$instance, 'tearDown'])) { |
|
203 | + if (is_callable([$instance, 'tearDown'])) { |
|
204 | 204 | $instance->tearDown(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | Resque_Event::trigger('afterPerform', $this); |
208 | 208 | } |
209 | 209 | // beforePerform/setUp have said don't perform this job. Return. |
210 | - catch(Resque_Job_DontPerform $e) { |
|
210 | + catch (Resque_Job_DontPerform $e) { |
|
211 | 211 | $result = false; |
212 | 212 | } |
213 | 213 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $monitor = false; |
256 | 256 | if (!empty($this->payload['id'])) { |
257 | 257 | $status = new Resque_Job_Status($this->payload['id'], $this->getPrefix()); |
258 | - if($status->isTracking()) { |
|
258 | + if ($status->isTracking()) { |
|
259 | 259 | $monitor = true; |
260 | 260 | } |
261 | 261 | } |
@@ -271,13 +271,13 @@ discard block |
||
271 | 271 | public function __toString() |
272 | 272 | { |
273 | 273 | $name = array( |
274 | - 'Job{' . $this->queue .'}' |
|
274 | + 'Job{' . $this->queue . '}' |
|
275 | 275 | ); |
276 | - if(!empty($this->payload['id'])) { |
|
276 | + if (!empty($this->payload['id'])) { |
|
277 | 277 | $name[] = 'ID: ' . $this->payload['id']; |
278 | 278 | } |
279 | 279 | $name[] = $this->payload['class']; |
280 | - if(!empty($this->payload['args'])) { |
|
280 | + if (!empty($this->payload['args'])) { |
|
281 | 281 | $name[] = json_encode($this->payload['args']); |
282 | 282 | } |
283 | 283 | return '(' . implode(' | ', $name) . ')'; |