@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | self::delayedPush($at, $job); |
| 48 | 48 | |
| 49 | 49 | Resque_Event::trigger('afterSchedule', array( |
| 50 | - array( |
|
| 51 | - 'at' => $at, |
|
| 52 | - 'queue' => $queue, |
|
| 53 | - 'class' => $class, |
|
| 54 | - 'args' => $args, |
|
| 55 | - ) |
|
| 56 | - )); |
|
| 50 | + array( |
|
| 51 | + 'at' => $at, |
|
| 52 | + 'queue' => $queue, |
|
| 53 | + 'class' => $class, |
|
| 54 | + 'args' => $args, |
|
| 55 | + ) |
|
| 56 | + )); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -93,59 +93,59 @@ discard block |
||
| 93 | 93 | return Resque::redis()->llen('delayed:' . $timestamp, $timestamp); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Remove a delayed job from the queue |
|
| 98 | - * |
|
| 99 | - * note: you must specify exactly the same |
|
| 100 | - * queue, class and arguments that you used when you added |
|
| 101 | - * to the delayed queue |
|
| 102 | - * |
|
| 103 | - * also, this is an expensive operation because all delayed keys have tobe |
|
| 104 | - * searched |
|
| 105 | - * |
|
| 106 | - * @param $queue |
|
| 107 | - * @param $class |
|
| 108 | - * @param $args |
|
| 109 | - * @return int number of jobs that were removed |
|
| 110 | - */ |
|
| 111 | - public static function removeDelayed($queue, $class, $args) |
|
| 112 | - { |
|
| 113 | - $destroyed=0; |
|
| 114 | - $item=json_encode(self::jobToHash($queue, $class, $args)); |
|
| 115 | - $redis=Resque::redis(); |
|
| 96 | + /** |
|
| 97 | + * Remove a delayed job from the queue |
|
| 98 | + * |
|
| 99 | + * note: you must specify exactly the same |
|
| 100 | + * queue, class and arguments that you used when you added |
|
| 101 | + * to the delayed queue |
|
| 102 | + * |
|
| 103 | + * also, this is an expensive operation because all delayed keys have tobe |
|
| 104 | + * searched |
|
| 105 | + * |
|
| 106 | + * @param $queue |
|
| 107 | + * @param $class |
|
| 108 | + * @param $args |
|
| 109 | + * @return int number of jobs that were removed |
|
| 110 | + */ |
|
| 111 | + public static function removeDelayed($queue, $class, $args) |
|
| 112 | + { |
|
| 113 | + $destroyed=0; |
|
| 114 | + $item=json_encode(self::jobToHash($queue, $class, $args)); |
|
| 115 | + $redis=Resque::redis(); |
|
| 116 | 116 | |
| 117 | - foreach($redis->keys('delayed:*') as $key) |
|
| 118 | - { |
|
| 119 | - $key=$redis->removePrefix($key); |
|
| 120 | - $destroyed+=$redis->lrem($key,0,$item); |
|
| 121 | - } |
|
| 117 | + foreach($redis->keys('delayed:*') as $key) |
|
| 118 | + { |
|
| 119 | + $key=$redis->removePrefix($key); |
|
| 120 | + $destroyed+=$redis->lrem($key,0,$item); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - return $destroyed; |
|
| 124 | - } |
|
| 123 | + return $destroyed; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * removed a delayed job queued for a specific timestamp |
|
| 128 | - * |
|
| 129 | - * note: you must specify exactly the same |
|
| 130 | - * queue, class and arguments that you used when you added |
|
| 131 | - * to the delayed queue |
|
| 132 | - * |
|
| 133 | - * @param $timestamp |
|
| 134 | - * @param $queue |
|
| 135 | - * @param $class |
|
| 136 | - * @param $args |
|
| 137 | - * @return mixed |
|
| 138 | - */ |
|
| 139 | - public static function removeDelayedJobFromTimestamp($timestamp, $queue, $class, $args) |
|
| 140 | - { |
|
| 141 | - $key = 'delayed:' . self::getTimestamp($timestamp); |
|
| 142 | - $item = json_encode(self::jobToHash($queue, $class, $args)); |
|
| 143 | - $redis = Resque::redis(); |
|
| 144 | - $count = $redis->lrem($key, 0, $item); |
|
| 145 | - self::cleanupTimestamp($key, $timestamp); |
|
| 126 | + /** |
|
| 127 | + * removed a delayed job queued for a specific timestamp |
|
| 128 | + * |
|
| 129 | + * note: you must specify exactly the same |
|
| 130 | + * queue, class and arguments that you used when you added |
|
| 131 | + * to the delayed queue |
|
| 132 | + * |
|
| 133 | + * @param $timestamp |
|
| 134 | + * @param $queue |
|
| 135 | + * @param $class |
|
| 136 | + * @param $args |
|
| 137 | + * @return mixed |
|
| 138 | + */ |
|
| 139 | + public static function removeDelayedJobFromTimestamp($timestamp, $queue, $class, $args) |
|
| 140 | + { |
|
| 141 | + $key = 'delayed:' . self::getTimestamp($timestamp); |
|
| 142 | + $item = json_encode(self::jobToHash($queue, $class, $args)); |
|
| 143 | + $redis = Resque::redis(); |
|
| 144 | + $count = $redis->lrem($key, 0, $item); |
|
| 145 | + self::cleanupTimestamp($key, $timestamp); |
|
| 146 | 146 | |
| 147 | - return $count; |
|
| 148 | - } |
|
| 147 | + return $count; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * Generate hash of all job properties to be saved in the scheduled queue. |
@@ -36,13 +36,13 @@ discard block |
||
| 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) { |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] .' [delayed]'); |
| 95 | 95 | |
| 96 | 96 | Resque_Event::trigger('beforeDelayedEnqueue', array( |
| 97 | - array( |
|
| 98 | - 'queue' => $item['queue'], |
|
| 99 | - 'class' => $item['class'], |
|
| 100 | - 'args' => $item['args'], |
|
| 101 | - ) |
|
| 102 | - )); |
|
| 97 | + array( |
|
| 98 | + 'queue' => $item['queue'], |
|
| 99 | + 'class' => $item['class'], |
|
| 100 | + 'args' => $item['args'], |
|
| 101 | + ) |
|
| 102 | + )); |
|
| 103 | 103 | |
| 104 | 104 | $payload = array_merge(array($item['queue'], $item['class']), $item['args']); |
| 105 | 105 | call_user_func_array('Resque::enqueue', $payload); |
@@ -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 | array( |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | private function updateProcLine($status) |
| 127 | 127 | { |
| 128 | - if(function_exists('setproctitle')) { |
|
| 128 | + if (function_exists('setproctitle')) { |
|
| 129 | 129 | setproctitle('resque-scheduler-' . ResqueScheduler::VERSION . ': ' . $status); |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function log($message) |
| 139 | 139 | { |
| 140 | - if($this->logLevel == self::LOG_NORMAL) { |
|
| 140 | + if ($this->logLevel == self::LOG_NORMAL) { |
|
| 141 | 141 | fwrite(STDOUT, "*** " . $message . "\n"); |
| 142 | 142 | } |
| 143 | - else if($this->logLevel == self::LOG_VERBOSE) { |
|
| 143 | + else if ($this->logLevel == self::LOG_VERBOSE) { |
|
| 144 | 144 | fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n"); |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | private function registerSigHandlers() |
| 156 | 156 | { |
| 157 | - if(!function_exists('pcntl_signal')) { |
|
| 157 | + if (!function_exists('pcntl_signal')) { |
|
| 158 | 158 | return; |
| 159 | 159 | } |
| 160 | 160 | |