- Timestamp:
- 05/14/2021 12:49:21 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/class-trac.php
r10000 r10972 42 42 43 43 try { 44 // Retrying this is safe, as the `_ts` parameter must be set correctly for it to succeed. 44 45 $this->api( 'ticket.update', [ $id, $comment, $attr, (bool) $notify, $author, $when ] ); 45 46 46 47 return true; 47 48 } catch( \Exception $e ) { 48 // Try once more.. `_ts` may have been outdated.49 // `_ts` may have been outdated, update and try again. 49 50 if ( isset( $get ) && $attr['_ts'] === $get['_ts'] ) { 50 51 $get = $this->get( $id ); // refetch the ticket. 51 $attr['_ts'] = $get['_ts']; 52 if ( $attr['_ts'] === $get['_ts'] ) { 53 // Didn't change, api already retried, throw it. 54 throw $e; 55 } 56 52 57 try { 58 $attr['_ts'] = $get['_ts']; 53 59 54 60 $this->api( 'ticket.update', [ $id, $comment, $attr, (bool) $notify, $author, $when ] ); … … 58 64 } 59 65 } 66 60 67 return false; 61 68 } … … 89 96 * Fetch/POST a Trac JSONRPC endpoint. 90 97 */ 91 public function api( $method, $params ) { 98 public function api( $method, $params, $retry = 3 ) { 99 $tries = 0; 100 $retry = (int) $retry; 101 102 do { 103 try { 104 return $this->_api( $method, $params ); 105 } catch( \Exception $e ) { 106 // Retry with a short delay 107 sleep( 1 ); 108 } 109 } while ( ++$tries < $retry ); 110 111 // If we make it this far, all retries have failed, throw that exception. 112 throw $e; 113 } 114 115 protected function _api( $method, $params ) { 92 116 $context = stream_context_create( [ 'http' => [ 93 117 'method' => 'POST', 94 118 'user_agent' => 'WordPress.org Trac; trac.WordPress.org', 95 119 'max_redirects' => 0, 96 'timeout' => 5,120 'timeout' => 30, 97 121 'ignore_errors' => true, 98 122 'header' => … … 140 164 'user_agent' => 'WordPress.org Trac; trac.WordPress.org', 141 165 'max_redirects' => 0, 142 'timeout' => 5,166 'timeout' => 30, 143 167 'ignore_errors' => true, 144 168 'header' => [
Note: See TracChangeset
for help on using the changeset viewer.