set_is_syncing() static public method

static public set_is_syncing ( $is_syncing )
コード例 #1
0
 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;
 }
コード例 #2
0
 protected function result()
 {
     $args = $this->input();
     $queue_name = $this->validate_queue($args['queue']);
     if (is_wp_error($queue_name)) {
         return $queue_name;
     }
     if ($args['number_of_items'] < 1 || $args['number_of_items'] > 100) {
         return new WP_Error('invalid_number_of_items', 'Number of items needs to be an integer that is larger than 0 and less then 100', 400);
     }
     require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-queue.php';
     $queue = new Jetpack_Sync_Queue($queue_name);
     if (0 === $queue->size()) {
         return new WP_Error('queue_size', 'The queue is empty and there is nothing to send', 400);
     }
     require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
     $sender = Jetpack_Sync_Sender::get_instance();
     // try to give ourselves as much time as possible
     set_time_limit(0);
     // let's delete the checkin state
     if ($args['force']) {
         $queue->unlock();
     }
     $buffer = $this->get_buffer($queue, $args['number_of_items']);
     // Check that the $buffer is not checkout out already
     if (is_wp_error($buffer)) {
         return new WP_Error('buffer_open', "We couldn't get the buffer it is currently checked out", 400);
     }
     if (!is_object($buffer)) {
         return new WP_Error('buffer_non-object', 'Buffer is not an object', 400);
     }
     Jetpack_Sync_Settings::set_is_syncing(true);
     list($items_to_send, $skipped_items_ids, $items) = $sender->get_items_to_send($buffer, $args['encode']);
     Jetpack_Sync_Settings::set_is_syncing(false);
     return array('buffer_id' => $buffer->id, 'items' => $items_to_send, 'skipped_items' => $skipped_items_ids, 'codec' => $args['encode'] ? $sender->get_codec()->name() : null, 'sent_timestamp' => time());
 }