@@ -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 |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param Worker $worker |
| 34 | 34 | * @param int $interval |
| 35 | 35 | */ |
| 36 | - public function __construct( $id, $worker, $interval ) { |
|
| 36 | + public function __construct($id, $worker, $interval) { |
|
| 37 | 37 | $this->id = $id; |
| 38 | 38 | $this->worker = $worker; |
| 39 | 39 | $this->interval = $interval; |
@@ -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( "wp_queue_worker_{$this->id}", array( $this, 'cron_worker' ) ); |
|
| 65 | + add_filter('cron_schedules', array($this, 'schedule_cron')); |
|
| 66 | + add_action("wp_queue_worker_{$this->id}", array($this, 'cron_worker')); |
|
| 67 | 67 | |
| 68 | - if ( ! wp_next_scheduled( "wp_queue_worker_{$this->id}" ) ) { |
|
| 68 | + if ( ! wp_next_scheduled("wp_queue_worker_{$this->id}")) { |
|
| 69 | 69 | // Schedule health check |
| 70 | - wp_schedule_event( time(), 'wp_queue_cron_interval', "wp_queue_worker_{$this->id}" ); |
|
| 70 | + wp_schedule_event(time(), 'wp_queue_cron_interval', "wp_queue_worker_{$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 ) { |
|
| 83 | + public function schedule_cron($schedules) { |
|
| 84 | 84 | $schedules["wp_queue_cron_interval_{$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; |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | public function cron_worker() { |
| 96 | 96 | $this->start_time = time(); |
| 97 | 97 | |
| 98 | - while ( ! $this->time_exceeded() && ! $this->memory_exceeded() ) { |
|
| 99 | - if ( ! $this->worker->process() ) { |
|
| 98 | + while ( ! $this->time_exceeded() && ! $this->memory_exceeded()) { |
|
| 99 | + if ( ! $this->worker->process()) { |
|
| 100 | 100 | break; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -112,14 +112,14 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | protected function memory_exceeded() { |
| 114 | 114 | $memory_limit = $this->get_memory_limit() * 0.8; // 80% of max memory |
| 115 | - $current_memory = memory_get_usage( true ); |
|
| 115 | + $current_memory = memory_get_usage(true); |
|
| 116 | 116 | $return = false; |
| 117 | 117 | |
| 118 | - if ( $current_memory >= $memory_limit ) { |
|
| 118 | + if ($current_memory >= $memory_limit) { |
|
| 119 | 119 | $return = true; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - return apply_filters( 'wp_queue_cron_memory_exceeded', $return ); |
|
| 122 | + return apply_filters('wp_queue_cron_memory_exceeded', $return); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -128,18 +128,18 @@ discard block |
||
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | protected function get_memory_limit() { |
| 131 | - if ( function_exists( 'ini_get' ) ) { |
|
| 132 | - $memory_limit = ini_get( 'memory_limit' ); |
|
| 131 | + if (function_exists('ini_get')) { |
|
| 132 | + $memory_limit = ini_get('memory_limit'); |
|
| 133 | 133 | } else { |
| 134 | 134 | $memory_limit = '256M'; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( ! $memory_limit || - 1 == $memory_limit ) { |
|
| 137 | + if ( ! $memory_limit || - 1 == $memory_limit) { |
|
| 138 | 138 | // Unlimited, set to 1GB |
| 139 | 139 | $memory_limit = '1000M'; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - return intval( $memory_limit ) * 1024 * 1024; |
|
| 142 | + return intval($memory_limit) * 1024 * 1024; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | * @return bool |
| 152 | 152 | */ |
| 153 | 153 | protected function time_exceeded() { |
| 154 | - $finish = $this->start_time + apply_filters( 'wp_queue_cron_time_limit', 20 ); // 20 seconds |
|
| 154 | + $finish = $this->start_time + apply_filters('wp_queue_cron_time_limit', 20); // 20 seconds |
|
| 155 | 155 | $return = false; |
| 156 | 156 | |
| 157 | - if ( time() >= $finish ) { |
|
| 157 | + if (time() >= $finish) { |
|
| 158 | 158 | $return = true; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - return apply_filters( 'wp_queue_cron_time_exceeded', $return ); |
|
| 161 | + return apply_filters('wp_queue_cron_time_exceeded', $return); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | \ 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 |