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