Making WordPress.org

Changeset 2559


Ignore:
Timestamp:
02/23/2016 03:21:23 PM (10 years ago)
Author:
iandunn
Message:

WordCamp QBO: Bump the remote request timeout to 10 seconds.

Some requests in production are timing out. For the most part, our error handling catches that gracefully, but there are some situations that still result in problems.

For instance, if we send a request to create an invoice, the QBO server receives it and proceses it, but doesn't respond in time, then we won't know that it was processed successfully, or the ID of the new invoice. If the deputy then tries to create the invoice again, a duplicate invoice will be created.

We may also need additional checks to prevent duplicates, but this should help mitigate similar problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/wordcamp-qbo.php

    r2533 r2559  
    55
    66class WordCamp_QBO {
     7    const REMOTE_REQUEST_TIMEOUT = 10; // seconds
     8
    79    private static $app_token;
    810    private static $consumer_key;
     
    166168            $oauth_header = $oauth->get_oauth_header( 'GET', $request_url );
    167169            $response = wp_remote_get( $request_url, array(
     170                'timeout' => self::REMOTE_REQUEST_TIMEOUT,
    168171                'headers' => array(
    169172                    'Authorization' => $oauth_header,
     
    189192        $oauth_header = $oauth->get_oauth_header( 'POST', $request_url, $payload );
    190193        $response = wp_remote_post( $request_url, array(
     194            'timeout' => self::REMOTE_REQUEST_TIMEOUT,
    191195            'headers' => array(
    192196                'Authorization' => $oauth_header,
     
    248252
    249253        $oauth_header = $oauth->get_oauth_header( 'GET', $request_url, $args );
    250         $response = wp_remote_get( esc_url_raw( add_query_arg( $args, $request_url ) ), array( 'headers' => array(
    251             'Authorization' => $oauth_header,
    252             'Accept' => 'application/json',
    253         ) ) );
     254        $response = wp_remote_get(
     255            esc_url_raw( add_query_arg( $args, $request_url ) ),
     256            array(
     257                'timeout' => self::REMOTE_REQUEST_TIMEOUT,
     258                'headers' => array(
     259                    'Authorization' => $oauth_header,
     260                    'Accept' => 'application/json',
     261                )
     262            )
     263        );
    254264
    255265        if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
     
    501511
    502512        $args = array(
     513            'timeout' => self::REMOTE_REQUEST_TIMEOUT,
    503514            'headers' => array(
    504515                'Authorization' => $oauth->get_oauth_header( 'POST', $request_url, $payload ),
     
    563574
    564575        $args = array(
     576            'timeout' => self::REMOTE_REQUEST_TIMEOUT,
    565577            'headers' => array(
    566578                'Authorization' => $oauth->get_oauth_header( 'POST', $request_url ),
     
    687699
    688700        $args = array(
     701            'timeout' => self::REMOTE_REQUEST_TIMEOUT,
    689702            'headers' => array(
    690703                'Authorization' => $oauth->get_oauth_header( 'GET', $request_url, $request_url_query ),
     
    824837
    825838        $args = array(
     839            'timeout' => self::REMOTE_REQUEST_TIMEOUT,
    826840            'headers' => array(
    827841                'Authorization' => $oauth->get_oauth_header( 'POST', $request_url, $payload ),
     
    921935
    922936        $args = array(
     937            'timeout' => self::REMOTE_REQUEST_TIMEOUT,
    923938            'headers' => array(
    924939                'Authorization' => $oauth->get_oauth_header( 'GET', $request_url, $request_url_query ),
     
    10311046
    10321047            $oauth_header = $oauth->get_oauth_header( 'GET', $request_url );
    1033             $response = wp_remote_get( $request_url, array( 'headers' => array(
    1034                 'Authorization' => $oauth_header,
    1035                 'Accept' => 'application/json',
    1036             ) ) );
     1048            $response = wp_remote_get( $request_url, array(
     1049                'timeout' => self::REMOTE_REQUEST_TIMEOUT,
     1050                'headers' => array(
     1051                    'Authorization' => $oauth_header,
     1052                    'Accept' => 'application/json',
     1053                )
     1054            ) );
    10371055
    10381056            if ( is_wp_error( $response ) ) {
Note: See TracChangeset for help on using the changeset viewer.