@@ -54,8 +54,8 @@ |
||
| 54 | 54 | |
| 55 | 55 | $PREFIX = getenv('PREFIX'); |
| 56 | 56 | if(!empty($PREFIX)) { |
| 57 | - fwrite(STDOUT, '*** Prefix set to '.$PREFIX."\n"); |
|
| 58 | - Resque_Redis::prefix($PREFIX); |
|
| 57 | + fwrite(STDOUT, '*** Prefix set to '.$PREFIX."\n"); |
|
| 58 | + Resque_Redis::prefix($PREFIX); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $worker = new ResqueScheduler_Worker(); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | $REDIS_BACKEND = getenv('REDIS_BACKEND'); |
| 18 | 18 | $REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB'); |
| 19 | -if(!empty($REDIS_BACKEND)) { |
|
| 19 | +if (!empty($REDIS_BACKEND)) { |
|
| 20 | 20 | if (empty($REDIS_BACKEND_DB)) |
| 21 | 21 | Resque::setBackend($REDIS_BACKEND); |
| 22 | 22 | else |
@@ -28,33 +28,33 @@ discard block |
||
| 28 | 28 | $LOGGING = getenv('LOGGING'); |
| 29 | 29 | $VERBOSE = getenv('VERBOSE'); |
| 30 | 30 | $VVERBOSE = getenv('VVERBOSE'); |
| 31 | -if(!empty($LOGGING) || !empty($VERBOSE)) { |
|
| 31 | +if (!empty($LOGGING) || !empty($VERBOSE)) { |
|
| 32 | 32 | $logLevel = ResqueScheduler_Worker::LOG_NORMAL; |
| 33 | 33 | } |
| 34 | -else if(!empty($VVERBOSE)) { |
|
| 34 | +else if (!empty($VVERBOSE)) { |
|
| 35 | 35 | $logLevel = ResqueScheduler_Worker::LOG_VERBOSE; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Check for jobs every $interval seconds |
| 39 | 39 | $interval = 5; |
| 40 | 40 | $INTERVAL = getenv('INTERVAL'); |
| 41 | -if(!empty($INTERVAL)) { |
|
| 41 | +if (!empty($INTERVAL)) { |
|
| 42 | 42 | $interval = $INTERVAL; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // Load the user's application if one exists |
| 46 | 46 | $APP_INCLUDE = getenv('APP_INCLUDE'); |
| 47 | -if($APP_INCLUDE) { |
|
| 48 | - if(!file_exists($APP_INCLUDE)) { |
|
| 49 | - die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n"); |
|
| 47 | +if ($APP_INCLUDE) { |
|
| 48 | + if (!file_exists($APP_INCLUDE)) { |
|
| 49 | + die('APP_INCLUDE (' . $APP_INCLUDE . ") does not exist.\n"); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | require_once $APP_INCLUDE; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $PREFIX = getenv('PREFIX'); |
| 56 | -if(!empty($PREFIX)) { |
|
| 57 | - fwrite(STDOUT, '*** Prefix set to '.$PREFIX."\n"); |
|
| 56 | +if (!empty($PREFIX)) { |
|
| 57 | + fwrite(STDOUT, '*** Prefix set to ' . $PREFIX . "\n"); |
|
| 58 | 58 | Resque_Redis::prefix($PREFIX); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -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; |
@@ -24,13 +24,13 @@ |
||
| 24 | 24 | protected $interval = 5; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * The primary loop for a worker. |
|
| 28 | - * |
|
| 29 | - * Every $interval (seconds), the scheduled queue will be checked for jobs |
|
| 30 | - * that should be pushed to Resque. |
|
| 31 | - * |
|
| 32 | - * @param int $interval How often to check schedules. |
|
| 33 | - */ |
|
| 27 | + * The primary loop for a worker. |
|
| 28 | + * |
|
| 29 | + * Every $interval (seconds), the scheduled queue will be checked for jobs |
|
| 30 | + * that should be pushed to Resque. |
|
| 31 | + * |
|
| 32 | + * @param int $interval How often to check schedules. |
|
| 33 | + */ |
|
| 34 | 34 | public function work($interval = null) |
| 35 | 35 | { |
| 36 | 36 | if ($interval !== null) { |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $item = null; |
| 75 | 75 | while ($item = ResqueScheduler::nextItemForTimestamp($timestamp)) { |
| 76 | - $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] .' [delayed]'); |
|
| 76 | + $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] . ' [delayed]'); |
|
| 77 | 77 | |
| 78 | 78 | Resque_Event::trigger('beforeDelayedEnqueue', array( |
| 79 | 79 | 'queue' => $item['queue'], |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | private function updateProcLine($status) |
| 107 | 107 | { |
| 108 | - if(function_exists('setproctitle')) { |
|
| 108 | + if (function_exists('setproctitle')) { |
|
| 109 | 109 | setproctitle('resque-scheduler-' . ResqueScheduler::VERSION . ': ' . $status); |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public function log($message) |
| 119 | 119 | { |
| 120 | - if($this->logLevel == self::LOG_NORMAL) { |
|
| 120 | + if ($this->logLevel == self::LOG_NORMAL) { |
|
| 121 | 121 | fwrite(STDOUT, "*** " . $message . "\n"); |
| 122 | 122 | } |
| 123 | - else if($this->logLevel == self::LOG_VERBOSE) { |
|
| 123 | + else if ($this->logLevel == self::LOG_VERBOSE) { |
|
| 124 | 124 | fwrite(STDOUT, "** [" . strftime('%T %Y-%m-%d') . "] " . $message . "\n"); |
| 125 | 125 | } |
| 126 | 126 | } |