public function do_sync_and_set_delays($queue)
{
// don't sync if importing
if (defined('WP_IMPORTING') && WP_IMPORTING) {
return false;
}
// don't sync if we are throttled
if ($this->get_next_sync_time($queue->id) > microtime(true)) {
return false;
}
$start_time = microtime(true);
Jetpack_Sync_Settings::set_is_syncing(true);
$sync_result = $this->do_sync_for_queue($queue);
Jetpack_Sync_Settings::set_is_syncing(false);
$exceeded_sync_wait_threshold = microtime(true) - $start_time > (double) $this->get_sync_wait_threshold();
if (is_wp_error($sync_result)) {
if ('unclosed_buffer' === $sync_result->get_error_code()) {
$this->set_next_sync_time(time() + self::QUEUE_LOCKED_SYNC_DELAY, $queue->id);
} else {
$this->set_next_sync_time(time() + self::WPCOM_ERROR_SYNC_DELAY, $queue->id);
}
$sync_result = false;
} elseif ($exceeded_sync_wait_threshold) {
// if we actually sent data and it took a while, wait before sending again
$this->set_next_sync_time(time() + $this->get_sync_wait_time(), $queue->id);
}
return $sync_result;
}