@@ -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 | } |
@@ -25,19 +25,19 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | protected $interval = 5; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var boolean True if on the next iteration, the worker should shutdown. |
|
| 30 | - */ |
|
| 31 | - private $shutdown = false; |
|
| 28 | + /** |
|
| 29 | + * @var boolean True if on the next iteration, the worker should shutdown. |
|
| 30 | + */ |
|
| 31 | + private $shutdown = false; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | - * The primary loop for a worker. |
|
| 35 | - * |
|
| 36 | - * Every $interval (seconds), the scheduled queue will be checked for jobs |
|
| 37 | - * that should be pushed to Resque. |
|
| 38 | - * |
|
| 39 | - * @param int $interval How often to check schedules. |
|
| 40 | - */ |
|
| 34 | + * The primary loop for a worker. |
|
| 35 | + * |
|
| 36 | + * Every $interval (seconds), the scheduled queue will be checked for jobs |
|
| 37 | + * that should be pushed to Resque. |
|
| 38 | + * |
|
| 39 | + * @param int $interval How often to check schedules. |
|
| 40 | + */ |
|
| 41 | 41 | public function work($interval = null) |
| 42 | 42 | { |
| 43 | 43 | if ($interval !== null) { |
@@ -47,10 +47,10 @@ discard block |
||
| 47 | 47 | $this->updateProcLine('Starting'); |
| 48 | 48 | $this->registerSigHandlers(); |
| 49 | 49 | |
| 50 | - while (true) { |
|
| 51 | - if($this->shutdown) { |
|
| 52 | - break; |
|
| 53 | - } |
|
| 50 | + while (true) { |
|
| 51 | + if($this->shutdown) { |
|
| 52 | + break; |
|
| 53 | + } |
|
| 54 | 54 | $this->handleDelayedItems(); |
| 55 | 55 | $this->sleep(); |
| 56 | 56 | } |
@@ -136,26 +136,26 @@ discard block |
||
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Register signal handlers that a worker should respond to. |
|
| 141 | - * |
|
| 142 | - * TERM: Shutdown immediately and stop processing jobs. |
|
| 143 | - * INT: Shutdown immediately and stop processing jobs. |
|
| 144 | - * QUIT: Shutdown after the current job finishes processing. |
|
| 145 | - */ |
|
| 146 | - private function registerSigHandlers() |
|
| 147 | - { |
|
| 148 | - if(!function_exists('pcntl_signal')) { |
|
| 149 | - return; |
|
| 150 | - } |
|
| 139 | + /** |
|
| 140 | + * Register signal handlers that a worker should respond to. |
|
| 141 | + * |
|
| 142 | + * TERM: Shutdown immediately and stop processing jobs. |
|
| 143 | + * INT: Shutdown immediately and stop processing jobs. |
|
| 144 | + * QUIT: Shutdown after the current job finishes processing. |
|
| 145 | + */ |
|
| 146 | + private function registerSigHandlers() |
|
| 147 | + { |
|
| 148 | + if(!function_exists('pcntl_signal')) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - pcntl_signal(SIGTERM, array($this, 'shutdown')); |
|
| 153 | - pcntl_signal(SIGINT, array($this, 'shutdown')); |
|
| 154 | - pcntl_signal(SIGQUIT, array($this, 'shutdown')); |
|
| 155 | - } |
|
| 152 | + pcntl_signal(SIGTERM, array($this, 'shutdown')); |
|
| 153 | + pcntl_signal(SIGINT, array($this, 'shutdown')); |
|
| 154 | + pcntl_signal(SIGQUIT, array($this, 'shutdown')); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - public function shutdown() |
|
| 158 | - { |
|
| 159 | - $this->shutdown = true; |
|
| 160 | - } |
|
| 157 | + public function shutdown() |
|
| 158 | + { |
|
| 159 | + $this->shutdown = true; |
|
| 160 | + } |
|
| 161 | 161 | } |
@@ -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. |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $this->registerSigHandlers(); |
| 49 | 49 | |
| 50 | 50 | while (true) { |
| 51 | - if($this->shutdown) { |
|
| 51 | + if ($this->shutdown) { |
|
| 52 | 52 | break; |
| 53 | 53 | } |
| 54 | 54 | $this->handleDelayedItems(); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | $item = null; |
| 86 | 86 | while ($item = ResqueScheduler::nextItemForTimestamp($timestamp)) { |
| 87 | - $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] .' [delayed]'); |
|
| 87 | + $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] . ' [delayed]'); |
|
| 88 | 88 | |
| 89 | 89 | Resque_Event::trigger('beforeDelayedEnqueue', array( |
| 90 | 90 | 'queue' => $item['queue'], |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | private function updateProcLine($status) |
| 118 | 118 | { |
| 119 | - if(function_exists('setproctitle')) { |
|
| 119 | + if (function_exists('setproctitle')) { |
|
| 120 | 120 | setproctitle('resque-scheduler-' . ResqueScheduler::VERSION . ': ' . $status); |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function log($message) |
| 130 | 130 | { |
| 131 | - if($this->logLevel == self::LOG_NORMAL) { |
|
| 131 | + if ($this->logLevel == self::LOG_NORMAL) { |
|
| 132 | 132 | fwrite(STDOUT, "*** " . $message . "\n"); |
| 133 | 133 | } |
| 134 | - else if($this->logLevel == self::LOG_VERBOSE) { |
|
| 134 | + else if ($this->logLevel == self::LOG_VERBOSE) { |
|
| 135 | 135 | fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n"); |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | private function registerSigHandlers() |
| 147 | 147 | { |
| 148 | - if(!function_exists('pcntl_signal')) { |
|
| 148 | + if (!function_exists('pcntl_signal')) { |
|
| 149 | 149 | return; |
| 150 | 150 | } |
| 151 | 151 | |