Пример #1
0
 /**
  * Make a reschedulable request to acknowledge updates.
  *
  * @since 1.3.0
  *
  * @param array $updates Array as returned by pull_updates
  * @param int $retry_wait_seconds Optional. One second default as this is a time-sensitive request.
  * @return bool|WP_Error status
  */
 public static function acknowledge_updates($updates, $retry_wait_seconds = 1)
 {
     $messenger = Prompt_Factory::make_inbound_messenger();
     $result = $messenger->acknowledge_updates($updates);
     $rescheduler = new Prompt_Rescheduler($result, $retry_wait_seconds);
     if ($rescheduler->found_temporary_error()) {
         $rescheduler->reschedule('prompt/inbound_handling/acknowledge_updates', array($updates));
         return $result;
     }
     if (is_wp_error($result)) {
         Prompt_Logging::add_wp_error($result);
     }
     return $result;
 }
Пример #2
0
 /**
  * Reschedule a job on an exponential decay timing scheme that increases wait times by a factor of 4.
  *
  * @since 1.3.0
  *
  * @param string $hook The hook to run
  * @param array $args The arguments minus retry_wait_seconds, which will be calculated as the last argument.
  */
 public function reschedule($hook, $args = array())
 {
     if (is_null($this->wait_seconds)) {
         Prompt_Logging::add_wp_error($this->job_result);
         return;
     }
     // Add a random factor to spread things out a little
     $retry_time = time() + $this->wait_seconds + rand(0, $this->wait_seconds / 50);
     $next_wait = $this->wait_seconds * 4;
     $one_day_in_seconds = 60 * 60 * 24;
     if ($next_wait > $one_day_in_seconds) {
         $next_wait = null;
     }
     $args[] = $next_wait;
     wp_schedule_single_event($retry_time, $hook, $args);
 }