| @@ 199-225 (lines=27) @@ | ||
| 196 | // try to send actions until we run out of things to send, |
|
| 197 | // or have to wait more than 15s before sending again, |
|
| 198 | // or we hit a lock or some other sending issue |
|
| 199 | static function do_cron_sync() { |
|
| 200 | if ( ! self::sync_allowed() ) { |
|
| 201 | return; |
|
| 202 | } |
|
| 203 | ||
| 204 | self::initialize_sender(); |
|
| 205 | ||
| 206 | // remove shutdown hook - no need to sync twice |
|
| 207 | if ( has_action( 'shutdown', array( self::$sender, 'do_sync' ) ) ) { |
|
| 208 | remove_action( 'shutdown', array( self::$sender, 'do_sync' ) ); |
|
| 209 | } |
|
| 210 | ||
| 211 | do { |
|
| 212 | $next_sync_time = self::$sender->get_next_sync_time( 'sync' ); |
|
| 213 | ||
| 214 | if ( $next_sync_time ) { |
|
| 215 | $delay = $next_sync_time - time() + 1; |
|
| 216 | if ( $delay > 15 ) { |
|
| 217 | break; |
|
| 218 | } elseif ( $delay > 0 ) { |
|
| 219 | sleep( $delay ); |
|
| 220 | } |
|
| 221 | } |
|
| 222 | ||
| 223 | $result = self::$sender->do_sync(); |
|
| 224 | } while ( $result ); |
|
| 225 | } |
|
| 226 | ||
| 227 | static function do_cron_full_sync() { |
|
| 228 | if ( ! self::sync_allowed() ) { |
|
| @@ 227-253 (lines=27) @@ | ||
| 224 | } while ( $result ); |
|
| 225 | } |
|
| 226 | ||
| 227 | static function do_cron_full_sync() { |
|
| 228 | if ( ! self::sync_allowed() ) { |
|
| 229 | return; |
|
| 230 | } |
|
| 231 | ||
| 232 | self::initialize_sender(); |
|
| 233 | ||
| 234 | // remove shutdown hook - no need to sync twice |
|
| 235 | if ( has_action( 'shutdown', array( self::$sender, 'do_sync' ) ) ) { |
|
| 236 | remove_action( 'shutdown', array( self::$sender, 'do_sync' ) ); |
|
| 237 | } |
|
| 238 | ||
| 239 | do { |
|
| 240 | $next_sync_time = self::$sender->get_next_sync_time( 'full_sync' ); |
|
| 241 | ||
| 242 | if ( $next_sync_time ) { |
|
| 243 | $delay = $next_sync_time - time() + 1; |
|
| 244 | if ( $delay > 15 ) { |
|
| 245 | break; |
|
| 246 | } elseif ( $delay > 0 ) { |
|
| 247 | sleep( $delay ); |
|
| 248 | } |
|
| 249 | } |
|
| 250 | ||
| 251 | $result = self::$sender->do_full_sync(); |
|
| 252 | } while ( $result ); |
|
| 253 | } |
|
| 254 | ||
| 255 | static function initialize_listener() { |
|
| 256 | require_once dirname( __FILE__ ) . '/class.jetpack-sync-listener.php'; |
|