self::STATUS_UNKNOWN, self::OPTION_TIMESTAMP_KEY => microtime( true ), ); switch ( $status ) { case self::STATUS_DISABLED: case self::STATUS_OUT_OF_SYNC: case self::STATUS_IN_SYNC: $new_status[ self::OPTION_STATUS_KEY ] = $status; break; } \Jetpack_Options::update_option( self::STATUS_OPTION, $new_status ); return true; } /** * Check if Status has been previously set. * * @return bool is a Status defined */ public static function is_status_defined() { $status = \Jetpack_Options::get_option( self::STATUS_OPTION ); if ( false === $status || ! is_array( $status ) || empty( $status[ self::OPTION_STATUS_KEY ] ) ) { return false; } else { return true; } } /** * Check if the sync queue is healthy based on size and lag. * * The queue is considered healthy if either size OR lag is within its limit. * This matches the logic in Listener::can_add_to_queue(): data loss only occurs * when both limits are exceeded simultaneously. * * @param int $queue_size Current queue size. * @param float $queue_lag Current queue lag in seconds. * @param int $max_queue_size Maximum allowed queue size. * @param float $max_queue_lag Maximum allowed queue lag in seconds. * @return bool Whether the queue is healthy. */ public static function is_queue_healthy( $queue_size, $queue_lag, $max_queue_size, $max_queue_lag ) { return ( $queue_size < $max_queue_size ) || ( $queue_lag < $max_queue_lag ); } /** * Update Sync Status if Full Sync ended of Posts * * @param string $checksum The checksum that's currently being processed. * @param array $range The ranges of object types being processed. */ public static function full_sync_end_update_status( $checksum, $range ) { if ( isset( $range['posts'] ) ) { self::update_status( self::STATUS_IN_SYNC ); } } }