@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use WP_Queue\Queue; |
| 4 | 4 | use WP_Queue\QueueManager; |
| 5 | 5 | |
| 6 | -if ( ! function_exists( 'wp_queue' ) ) { |
|
| 6 | +if ( ! function_exists('wp_queue')) { |
|
| 7 | 7 | /** |
| 8 | 8 | * Return Queue instance. |
| 9 | 9 | * |
@@ -11,19 +11,19 @@ discard block |
||
| 11 | 11 | * |
| 12 | 12 | * @return Queue |
| 13 | 13 | */ |
| 14 | - function wp_queue( $connection = 'database' ) { |
|
| 15 | - return QueueManager::resolve( $connection ); |
|
| 14 | + function wp_queue($connection = 'database') { |
|
| 15 | + return QueueManager::resolve($connection); |
|
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -if ( ! function_exists( 'wp_queue_install_tables' ) ) { |
|
| 19 | +if ( ! function_exists('wp_queue_install_tables')) { |
|
| 20 | 20 | /** |
| 21 | 21 | * Install database tables |
| 22 | 22 | */ |
| 23 | 23 | function wp_queue_install_tables() { |
| 24 | 24 | global $wpdb; |
| 25 | 25 | |
| 26 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 26 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 27 | 27 | |
| 28 | 28 | $wpdb->hide_errors(); |
| 29 | 29 | $charset_collate = $wpdb->get_charset_collate(); |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | PRIMARY KEY (id) |
| 39 | 39 | ) $charset_collate;"; |
| 40 | 40 | |
| 41 | - dbDelta( $sql ); |
|
| 41 | + dbDelta($sql); |
|
| 42 | 42 | |
| 43 | 43 | $sql = "CREATE TABLE {$wpdb->prefix}queue_failures ( |
| 44 | 44 | id bigint(20) NOT NULL AUTO_INCREMENT, |
@@ -48,6 +48,6 @@ discard block |
||
| 48 | 48 | PRIMARY KEY (id) |
| 49 | 49 | ) $charset_collate;"; |
| 50 | 50 | |
| 51 | - dbDelta( $sql ); |
|
| 51 | + dbDelta($sql); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param ConnectionInterface $connection |
| 24 | 24 | * @param int $attempts |
| 25 | 25 | */ |
| 26 | - public function __construct( $connection, $attempts = 3 ) { |
|
| 26 | + public function __construct($connection, $attempts = 3) { |
|
| 27 | 27 | $this->connection = $connection; |
| 28 | 28 | $this->attempts = $attempts; |
| 29 | 29 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | public function process() { |
| 37 | 37 | $job = $this->connection->pop(); |
| 38 | 38 | |
| 39 | - if ( ! $job ) { |
|
| 39 | + if ( ! $job) { |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -44,20 +44,20 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | try { |
| 46 | 46 | $job->handle(); |
| 47 | - } catch ( Exception $exception ) { |
|
| 47 | + } catch (Exception $exception) { |
|
| 48 | 48 | $job->release(); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if ( $job->attempts() >= $this->attempts ) { |
|
| 51 | + if ($job->attempts() >= $this->attempts) { |
|
| 52 | 52 | $job->fail(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ( $job->failed() ) { |
|
| 56 | - $this->connection->failure( $job, $exception ); |
|
| 57 | - } else if ( $job->released() ) { |
|
| 58 | - $this->connection->release( $job ); |
|
| 55 | + if ($job->failed()) { |
|
| 56 | + $this->connection->failure($job, $exception); |
|
| 57 | + } else if ($job->released()) { |
|
| 58 | + $this->connection->release($job); |
|
| 59 | 59 | } else { |
| 60 | - $this->connection->delete( $job ); |
|
| 60 | + $this->connection->delete($job); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | return true; |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return bool|int |
| 17 | 17 | */ |
| 18 | - public function push( Job $job, $delay = 0 ) { |
|
| 18 | + public function push(Job $job, $delay = 0) { |
|
| 19 | 19 | // |
| 20 | 20 | } |
| 21 | 21 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @param Job $job |
| 35 | 35 | */ |
| 36 | - public function delete( $job ) { |
|
| 36 | + public function delete($job) { |
|
| 37 | 37 | // |
| 38 | 38 | } |
| 39 | 39 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @param Job $job |
| 44 | 44 | */ |
| 45 | - public function release( $job ) { |
|
| 45 | + public function release($job) { |
|
| 46 | 46 | // |
| 47 | 47 | } |
| 48 | 48 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param Job $job |
| 53 | 53 | * @param Exception $exception |
| 54 | 54 | */ |
| 55 | - public function failure( $job, Exception $exception ) { |
|
| 55 | + public function failure($job, Exception $exception) { |
|
| 56 | 56 | // |
| 57 | 57 | } |
| 58 | 58 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return bool|int |
| 17 | 17 | */ |
| 18 | - public function push( Job $job, $delay = 0 ); |
|
| 18 | + public function push(Job $job, $delay = 0); |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Retrieve a job from the queue. |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param Job $job |
| 31 | 31 | */ |
| 32 | - public function delete( $job ); |
|
| 32 | + public function delete($job); |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Release a job back onto the queue. |
| 36 | 36 | * |
| 37 | 37 | * @param Job $job |
| 38 | 38 | */ |
| 39 | - public function release( $job ); |
|
| 39 | + public function release($job); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Push a job onto the failure queue. |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return |
| 48 | 48 | */ |
| 49 | - public function failure( $job, Exception $exception ); |
|
| 49 | + public function failure($job, Exception $exception); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Get total jobs in the queue. |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @param int $id |
| 63 | 63 | */ |
| 64 | - public function set_id( $id ) { |
|
| 64 | + public function set_id($id) { |
|
| 65 | 65 | $this->id = $id; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @param int $attempts |
| 81 | 81 | */ |
| 82 | - public function set_attempts( $attempts ) { |
|
| 82 | + public function set_attempts($attempts) { |
|
| 83 | 83 | $this->attempts = $attempts; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @param null|Carbon $reserved_at |
| 99 | 99 | */ |
| 100 | - public function set_reserved_at( $reserved_at ) { |
|
| 100 | + public function set_reserved_at($reserved_at) { |
|
| 101 | 101 | $this->reserved_at = $reserved_at; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @param Carbon $available_at |
| 117 | 117 | */ |
| 118 | - public function set_available_at( Carbon $available_at ) { |
|
| 118 | + public function set_available_at(Carbon $available_at) { |
|
| 119 | 119 | $this->available_at = $available_at; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @param Carbon $created_at |
| 135 | 135 | */ |
| 136 | - public function set_created_at( Carbon $created_at ) { |
|
| 136 | + public function set_created_at(Carbon $created_at) { |
|
| 137 | 137 | $this->created_at = $created_at; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * @return array |
| 177 | 177 | */ |
| 178 | 178 | public function __sleep() { |
| 179 | - $object_props = get_object_vars( $this ); |
|
| 179 | + $object_props = get_object_vars($this); |
|
| 180 | 180 | $excluded_props = array( |
| 181 | 181 | 'id', |
| 182 | 182 | 'attempts', |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | 'failed', |
| 188 | 188 | ); |
| 189 | 189 | |
| 190 | - foreach ( $excluded_props as $prop ) { |
|
| 191 | - unset( $object_props[ $prop ] ); |
|
| 190 | + foreach ($excluded_props as $prop) { |
|
| 191 | + unset($object_props[$prop]); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - return array_keys( $object_props ); |
|
| 194 | + return array_keys($object_props); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | } |
| 198 | 198 | \ No newline at end of file |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @param wpdb $wpdb |
| 30 | 30 | */ |
| 31 | - public function __construct( $wpdb ) { |
|
| 31 | + public function __construct($wpdb) { |
|
| 32 | 32 | $this->database = $wpdb; |
| 33 | 33 | $this->jobs_table = $this->database->prefix . 'queue_jobs'; |
| 34 | 34 | $this->failures_table = $this->database->prefix . 'queue_failures'; |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return bool|int |
| 44 | 44 | */ |
| 45 | - public function push( Job $job, $delay = 0 ) { |
|
| 46 | - $result = $this->database->insert( $this->jobs_table, array( |
|
| 47 | - 'job' => serialize( $job ), |
|
| 48 | - 'available_at' => $this->datetime( $delay ), |
|
| 45 | + public function push(Job $job, $delay = 0) { |
|
| 46 | + $result = $this->database->insert($this->jobs_table, array( |
|
| 47 | + 'job' => serialize($job), |
|
| 48 | + 'available_at' => $this->datetime($delay), |
|
| 49 | 49 | 'created_at' => $this->datetime(), |
| 50 | - ) ); |
|
| 50 | + )); |
|
| 51 | 51 | |
| 52 | - if ( ! $result ) { |
|
| 52 | + if ( ! $result) { |
|
| 53 | 53 | return false; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -64,23 +64,23 @@ discard block |
||
| 64 | 64 | public function pop() { |
| 65 | 65 | $this->release_reserved(); |
| 66 | 66 | |
| 67 | - $sql = $this->database->prepare( " |
|
| 67 | + $sql = $this->database->prepare(" |
|
| 68 | 68 | SELECT * FROM {$this->jobs_table} |
| 69 | 69 | WHERE reserved_at IS NULL |
| 70 | 70 | AND available_at <= %s |
| 71 | 71 | ORDER BY available_at |
| 72 | 72 | LIMIT 1 |
| 73 | - ", $this->datetime() ); |
|
| 73 | + ", $this->datetime()); |
|
| 74 | 74 | |
| 75 | - $raw_job = $this->database->get_row( $sql ); |
|
| 75 | + $raw_job = $this->database->get_row($sql); |
|
| 76 | 76 | |
| 77 | - if ( is_null( $raw_job ) ) { |
|
| 77 | + if (is_null($raw_job)) { |
|
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $job = $this->vitalize_job( $raw_job ); |
|
| 81 | + $job = $this->vitalize_job($raw_job); |
|
| 82 | 82 | |
| 83 | - $this->reserve( $job ); |
|
| 83 | + $this->reserve($job); |
|
| 84 | 84 | |
| 85 | 85 | return $job; |
| 86 | 86 | } |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return bool |
| 94 | 94 | */ |
| 95 | - public function delete( $job ) { |
|
| 95 | + public function delete($job) { |
|
| 96 | 96 | $where = array( |
| 97 | 97 | 'id' => $job->id(), |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | - if ( $this->database->delete( $this->jobs_table, $where ) ) { |
|
| 100 | + if ($this->database->delete($this->jobs_table, $where)) { |
|
| 101 | 101 | return true; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return bool |
| 113 | 113 | */ |
| 114 | - public function release( $job ) { |
|
| 115 | - $data = array( |
|
| 116 | - 'job' => serialize( $job ), |
|
| 114 | + public function release($job) { |
|
| 115 | + $data = array( |
|
| 116 | + 'job' => serialize($job), |
|
| 117 | 117 | 'attempts' => $job->attempts(), |
| 118 | 118 | 'reserved_at' => null, |
| 119 | 119 | ); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | 'id' => $job->id(), |
| 122 | 122 | ); |
| 123 | 123 | |
| 124 | - if ( $this->database->update( $this->jobs_table, $data, $where ) ) { |
|
| 124 | + if ($this->database->update($this->jobs_table, $data, $where)) { |
|
| 125 | 125 | return true; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -136,15 +136,15 @@ discard block |
||
| 136 | 136 | * |
| 137 | 137 | * @return bool |
| 138 | 138 | */ |
| 139 | - public function failure( $job, Exception $exception ) { |
|
| 140 | - $insert = $this->database->insert( $this->failures_table, array( |
|
| 141 | - 'job' => serialize( $job ), |
|
| 142 | - 'error' => $this->format_exception( $exception ), |
|
| 139 | + public function failure($job, Exception $exception) { |
|
| 140 | + $insert = $this->database->insert($this->failures_table, array( |
|
| 141 | + 'job' => serialize($job), |
|
| 142 | + 'error' => $this->format_exception($exception), |
|
| 143 | 143 | 'failed_at' => $this->datetime(), |
| 144 | - ) ); |
|
| 144 | + )); |
|
| 145 | 145 | |
| 146 | - if ( $insert ) { |
|
| 147 | - $this->delete( $job ); |
|
| 146 | + if ($insert) { |
|
| 147 | + $this->delete($job); |
|
| 148 | 148 | |
| 149 | 149 | return true; |
| 150 | 150 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | public function jobs() { |
| 161 | 161 | $sql = "SELECT COUNT(*) FROM {$this->jobs_table}"; |
| 162 | 162 | |
| 163 | - return (int) $this->database->get_var( $sql ); |
|
| 163 | + return (int) $this->database->get_var($sql); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | public function failed_jobs() { |
| 172 | 172 | $sql = "SELECT COUNT(*) FROM {$this->failures_table}"; |
| 173 | 173 | |
| 174 | - return (int) $this->database->get_var( $sql ); |
|
| 174 | + return (int) $this->database->get_var($sql); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @param Job $job |
| 181 | 181 | */ |
| 182 | - protected function reserve( $job ) { |
|
| 182 | + protected function reserve($job) { |
|
| 183 | 183 | $data = array( |
| 184 | 184 | 'reserved_at' => $this->datetime(), |
| 185 | 185 | ); |
| 186 | 186 | |
| 187 | - $this->database->update( $this->jobs_table, $data, array( |
|
| 187 | + $this->database->update($this->jobs_table, $data, array( |
|
| 188 | 188 | 'id' => $job->id(), |
| 189 | - ) ); |
|
| 189 | + )); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | protected function release_reserved() { |
| 196 | 196 | $expired = $this->datetime( -300 ); |
| 197 | 197 | |
| 198 | - $sql = $this->database->prepare( " |
|
| 198 | + $sql = $this->database->prepare(" |
|
| 199 | 199 | UPDATE {$this->jobs_table} |
| 200 | 200 | SET attempts = attempts + 1, reserved_at = NULL |
| 201 | - WHERE reserved_at <= %s", $expired ); |
|
| 201 | + WHERE reserved_at <= %s", $expired); |
|
| 202 | 202 | |
| 203 | - $this->database->query( $sql ); |
|
| 203 | + $this->database->query($sql); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -210,14 +210,14 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @return Job |
| 212 | 212 | */ |
| 213 | - protected function vitalize_job( $raw_job ) { |
|
| 214 | - $job = unserialize( $raw_job->job ); |
|
| 213 | + protected function vitalize_job($raw_job) { |
|
| 214 | + $job = unserialize($raw_job->job); |
|
| 215 | 215 | |
| 216 | - $job->set_id( $raw_job->id ); |
|
| 217 | - $job->set_attempts( $raw_job->attempts ); |
|
| 218 | - $job->set_reserved_at( empty( $raw_job->reserved_at ) ? null : new Carbon( $raw_job->reserved_at ) ); |
|
| 219 | - $job->set_available_at( new Carbon( $raw_job->available_at ) ); |
|
| 220 | - $job->set_created_at( new Carbon( $raw_job->created_at ) ); |
|
| 216 | + $job->set_id($raw_job->id); |
|
| 217 | + $job->set_attempts($raw_job->attempts); |
|
| 218 | + $job->set_reserved_at(empty($raw_job->reserved_at) ? null : new Carbon($raw_job->reserved_at)); |
|
| 219 | + $job->set_available_at(new Carbon($raw_job->available_at)); |
|
| 220 | + $job->set_created_at(new Carbon($raw_job->created_at)); |
|
| 221 | 221 | |
| 222 | 222 | return $job; |
| 223 | 223 | } |
@@ -229,10 +229,10 @@ discard block |
||
| 229 | 229 | * |
| 230 | 230 | * @return string |
| 231 | 231 | */ |
| 232 | - protected function datetime( $offset = 0 ) { |
|
| 232 | + protected function datetime($offset = 0) { |
|
| 233 | 233 | $timestamp = time() + $offset; |
| 234 | 234 | |
| 235 | - return gmdate( 'Y-m-d H:i:s', $timestamp ); |
|
| 235 | + return gmdate('Y-m-d H:i:s', $timestamp); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @return null|string |
| 244 | 244 | */ |
| 245 | - protected function format_exception( Exception $exception ) { |
|
| 246 | - if ( is_null( $exception ) ) { |
|
| 245 | + protected function format_exception(Exception $exception) { |
|
| 246 | + if (is_null($exception)) { |
|
| 247 | 247 | return null; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $class = get_class( $exception ); |
|
| 250 | + $class = get_class($exception); |
|
| 251 | 251 | |
| 252 | 252 | return "{$class}: {$exception->getMessage()} (#{$exception->getCode()})"; |
| 253 | 253 | } |
@@ -20,12 +20,12 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return Queue |
| 22 | 22 | */ |
| 23 | - public static function resolve( $connection ) { |
|
| 24 | - if ( isset( static::$instances[ $connection ] ) ) { |
|
| 25 | - return static::$instances[ $connection ]; |
|
| 23 | + public static function resolve($connection) { |
|
| 24 | + if (isset(static::$instances[$connection])) { |
|
| 25 | + return static::$instances[$connection]; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - return static::build( $connection ); |
|
| 28 | + return static::build($connection); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -36,16 +36,16 @@ discard block |
||
| 36 | 36 | * @return Queue |
| 37 | 37 | * @throws \Exception |
| 38 | 38 | */ |
| 39 | - protected static function build( $connection ) { |
|
| 39 | + protected static function build($connection) { |
|
| 40 | 40 | $connections = static::connections(); |
| 41 | 41 | |
| 42 | - if ( empty( $connections[ $connection ] ) ) { |
|
| 42 | + if (empty($connections[$connection])) { |
|
| 43 | 43 | throw new ConnectionNotFoundException(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - static::$instances[ $connection ] = new Queue( $connections[ $connection ] ); |
|
| 46 | + static::$instances[$connection] = new Queue($connections[$connection]); |
|
| 47 | 47 | |
| 48 | - return static::$instances[ $connection ]; |
|
| 48 | + return static::$instances[$connection]; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | protected static function connections() { |
| 57 | 57 | $connections = array( |
| 58 | - 'database' => new DatabaseConnection( $GLOBALS['wpdb'] ), |
|
| 58 | + 'database' => new DatabaseConnection($GLOBALS['wpdb']), |
|
| 59 | 59 | 'redis' => new RedisConnection(), |
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | - return apply_filters( 'wp_queue_connections', $connections ); |
|
| 62 | + return apply_filters('wp_queue_connections', $connections); |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | \ No newline at end of file |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @param ConnectionInterface $connection |
| 23 | 23 | */ |
| 24 | - public function __construct( ConnectionInterface $connection ) { |
|
| 24 | + public function __construct(ConnectionInterface $connection) { |
|
| 25 | 25 | $this->connection = $connection; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return bool|int |
| 35 | 35 | */ |
| 36 | - public function push( Job $job, $delay = 0 ) { |
|
| 37 | - return $this->connection->push( $job, $delay ); |
|
| 36 | + public function push(Job $job, $delay = 0) { |
|
| 37 | + return $this->connection->push($job, $delay); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return Cron |
| 47 | 47 | */ |
| 48 | - public function cron( $attempts = 3, $interval = 5 ) { |
|
| 49 | - if ( is_null( $this->cron ) ) { |
|
| 50 | - $this->cron = new Cron( get_class( $this->connection ), $this->worker( $attempts ), $interval ); |
|
| 48 | + public function cron($attempts = 3, $interval = 5) { |
|
| 49 | + if (is_null($this->cron)) { |
|
| 50 | + $this->cron = new Cron(get_class($this->connection), $this->worker($attempts), $interval); |
|
| 51 | 51 | $this->cron->init(); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return Worker |
| 63 | 63 | */ |
| 64 | - public function worker( $attempts ) { |
|
| 65 | - return new Worker( $this->connection, $attempts ); |
|
| 64 | + public function worker($attempts) { |
|
| 65 | + return new Worker($this->connection, $attempts); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | \ No newline at end of file |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | * @param Worker $worker |
| 34 | 34 | * @param int $interval |
| 35 | 35 | */ |
| 36 | - public function __construct( $id, $worker, $interval ) { |
|
| 37 | - $this->id = strtolower( str_replace( '\\', '_', $id ) ); |
|
| 36 | + public function __construct($id, $worker, $interval) { |
|
| 37 | + $this->id = strtolower(str_replace('\\', '_', $id)); |
|
| 38 | 38 | $this->worker = $worker; |
| 39 | 39 | $this->interval = $interval; |
| 40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @return bool |
| 46 | 46 | */ |
| 47 | 47 | protected function is_enabled() { |
| 48 | - if ( defined( 'DISABLE_WP_QUEUE_CRON' ) && DISABLE_WP_QUEUE_CRON ) { |
|
| 48 | + if (defined('DISABLE_WP_QUEUE_CRON') && DISABLE_WP_QUEUE_CRON) { |
|
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -58,16 +58,16 @@ discard block |
||
| 58 | 58 | * @return bool |
| 59 | 59 | */ |
| 60 | 60 | public function init() { |
| 61 | - if ( ! $this->is_enabled() ) { |
|
| 61 | + if ( ! $this->is_enabled()) { |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - add_filter( 'cron_schedules', array( $this, 'schedule_cron' ) ); |
|
| 66 | - add_action( $this->id, array( $this, 'cron_worker' ) ); |
|
| 65 | + add_filter('cron_schedules', array($this, 'schedule_cron')); |
|
| 66 | + add_action($this->id, array($this, 'cron_worker')); |
|
| 67 | 67 | |
| 68 | - if ( ! wp_next_scheduled( $this->id ) ) { |
|
| 68 | + if ( ! wp_next_scheduled($this->id)) { |
|
| 69 | 69 | // Schedule health check |
| 70 | - wp_schedule_event( time(), $this->id, $this->id ); |
|
| 70 | + wp_schedule_event(time(), $this->id, $this->id); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | return true; |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | - public function schedule_cron( $schedules ) { |
|
| 84 | - $schedules[ $this->id ] = array( |
|
| 83 | + public function schedule_cron($schedules) { |
|
| 84 | + $schedules[$this->id] = array( |
|
| 85 | 85 | 'interval' => MINUTE_IN_SECONDS * $this->interval, |
| 86 | - 'display' => sprintf( __( 'Every %d Minutes' ), $this->interval ), |
|
| 86 | + 'display' => sprintf(__('Every %d Minutes'), $this->interval), |
|
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | 89 | return $schedules; |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * Process any jobs in the queue. |
| 94 | 94 | */ |
| 95 | 95 | public function cron_worker() { |
| 96 | - if ( $this->is_worker_locked() ) { |
|
| 96 | + if ($this->is_worker_locked()) { |
|
| 97 | 97 | return; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | $this->lock_worker(); |
| 103 | 103 | |
| 104 | - while ( ! $this->time_exceeded() && ! $this->memory_exceeded() ) { |
|
| 105 | - if ( ! $this->worker->process() ) { |
|
| 104 | + while ( ! $this->time_exceeded() && ! $this->memory_exceeded()) { |
|
| 105 | + if ( ! $this->worker->process()) { |
|
| 106 | 106 | break; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -116,21 +116,21 @@ discard block |
||
| 116 | 116 | * @return bool |
| 117 | 117 | */ |
| 118 | 118 | protected function is_worker_locked() { |
| 119 | - return (bool) get_site_transient( $this->id ); |
|
| 119 | + return (bool) get_site_transient($this->id); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * Lock the cron worker. |
| 124 | 124 | */ |
| 125 | 125 | protected function lock_worker() { |
| 126 | - set_site_transient( $this->id, time(), 300 ); |
|
| 126 | + set_site_transient($this->id, time(), 300); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * Unlock the cron worker. |
| 131 | 131 | */ |
| 132 | 132 | protected function unlock_worker() { |
| 133 | - delete_site_transient( $this->id ); |
|
| 133 | + delete_site_transient($this->id); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -143,14 +143,14 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | protected function memory_exceeded() { |
| 145 | 145 | $memory_limit = $this->get_memory_limit() * 0.8; // 80% of max memory |
| 146 | - $current_memory = memory_get_usage( true ); |
|
| 146 | + $current_memory = memory_get_usage(true); |
|
| 147 | 147 | $return = false; |
| 148 | 148 | |
| 149 | - if ( $current_memory >= $memory_limit ) { |
|
| 149 | + if ($current_memory >= $memory_limit) { |
|
| 150 | 150 | $return = true; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - return apply_filters( 'wp_queue_cron_memory_exceeded', $return ); |
|
| 153 | + return apply_filters('wp_queue_cron_memory_exceeded', $return); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -159,18 +159,18 @@ discard block |
||
| 159 | 159 | * @return int |
| 160 | 160 | */ |
| 161 | 161 | protected function get_memory_limit() { |
| 162 | - if ( function_exists( 'ini_get' ) ) { |
|
| 163 | - $memory_limit = ini_get( 'memory_limit' ); |
|
| 162 | + if (function_exists('ini_get')) { |
|
| 163 | + $memory_limit = ini_get('memory_limit'); |
|
| 164 | 164 | } else { |
| 165 | 165 | $memory_limit = '256M'; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( ! $memory_limit || - 1 == $memory_limit ) { |
|
| 168 | + if ( ! $memory_limit || - 1 == $memory_limit) { |
|
| 169 | 169 | // Unlimited, set to 1GB |
| 170 | 170 | $memory_limit = '1000M'; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - return intval( $memory_limit ) * 1024 * 1024; |
|
| 173 | + return intval($memory_limit) * 1024 * 1024; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -182,13 +182,13 @@ discard block |
||
| 182 | 182 | * @return bool |
| 183 | 183 | */ |
| 184 | 184 | protected function time_exceeded() { |
| 185 | - $finish = $this->start_time + apply_filters( 'wp_queue_cron_time_limit', 20 ); // 20 seconds |
|
| 185 | + $finish = $this->start_time + apply_filters('wp_queue_cron_time_limit', 20); // 20 seconds |
|
| 186 | 186 | $return = false; |
| 187 | 187 | |
| 188 | - if ( time() >= $finish ) { |
|
| 188 | + if (time() >= $finish) { |
|
| 189 | 189 | $return = true; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - return apply_filters( 'wp_queue_cron_time_exceeded', $return ); |
|
| 192 | + return apply_filters('wp_queue_cron_time_exceeded', $return); |
|
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | \ No newline at end of file |