| @@ 243-269 (lines=27) @@ | ||
| 240 | // try to send actions until we run out of things to send, |
|
| 241 | // or have to wait more than 15s before sending again, |
|
| 242 | // or we hit a lock or some other sending issue |
|
| 243 | static function do_cron_sync() { |
|
| 244 | if ( ! self::sync_allowed() ) { |
|
| 245 | return; |
|
| 246 | } |
|
| 247 | ||
| 248 | self::initialize_sender(); |
|
| 249 | ||
| 250 | // remove shutdown hook - no need to sync twice |
|
| 251 | if ( has_action( 'shutdown', array( self::$sender, 'do_sync' ) ) ) { |
|
| 252 | remove_action( 'shutdown', array( self::$sender, 'do_sync' ) ); |
|
| 253 | } |
|
| 254 | ||
| 255 | do { |
|
| 256 | $next_sync_time = self::$sender->get_next_sync_time( 'sync' ); |
|
| 257 | ||
| 258 | if ( $next_sync_time ) { |
|
| 259 | $delay = $next_sync_time - time() + 1; |
|
| 260 | if ( $delay > 15 ) { |
|
| 261 | break; |
|
| 262 | } elseif ( $delay > 0 ) { |
|
| 263 | sleep( $delay ); |
|
| 264 | } |
|
| 265 | } |
|
| 266 | ||
| 267 | $result = self::$sender->do_sync(); |
|
| 268 | } while ( $result ); |
|
| 269 | } |
|
| 270 | ||
| 271 | static function do_cron_full_sync() { |
|
| 272 | if ( ! self::sync_allowed() ) { |
|
| @@ 271-297 (lines=27) @@ | ||
| 268 | } while ( $result ); |
|
| 269 | } |
|
| 270 | ||
| 271 | static function do_cron_full_sync() { |
|
| 272 | if ( ! self::sync_allowed() ) { |
|
| 273 | return; |
|
| 274 | } |
|
| 275 | ||
| 276 | self::initialize_sender(); |
|
| 277 | ||
| 278 | // remove shutdown hook - no need to sync twice |
|
| 279 | if ( has_action( 'shutdown', array( self::$sender, 'do_sync' ) ) ) { |
|
| 280 | remove_action( 'shutdown', array( self::$sender, 'do_sync' ) ); |
|
| 281 | } |
|
| 282 | ||
| 283 | do { |
|
| 284 | $next_sync_time = self::$sender->get_next_sync_time( 'full_sync' ); |
|
| 285 | ||
| 286 | if ( $next_sync_time ) { |
|
| 287 | $delay = $next_sync_time - time() + 1; |
|
| 288 | if ( $delay > 15 ) { |
|
| 289 | break; |
|
| 290 | } elseif ( $delay > 0 ) { |
|
| 291 | sleep( $delay ); |
|
| 292 | } |
|
| 293 | } |
|
| 294 | ||
| 295 | $result = self::$sender->do_full_sync(); |
|
| 296 | } while ( $result ); |
|
| 297 | } |
|
| 298 | ||
| 299 | static function initialize_listener() { |
|
| 300 | require_once dirname( __FILE__ ) . '/class.jetpack-sync-listener.php'; |
|