Changeset 3424471
- Timestamp:
- 12/21/2025 06:26:34 AM (3 months ago)
- Location:
- weather-write/trunk
- Files:
-
- 4 edited
-
includes/class-openmeteo.php (modified) (1 diff)
-
includes/class-reintent.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
weather-write.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
weather-write/trunk/includes/class-openmeteo.php
r3385542 r3424471 74 74 $url = add_query_arg( $args, 'https://api.open-meteo.com/v1/forecast' ); 75 75 76 $response = wp_remote_get( $url, [ 'timeout' => 25, 'headers' => [ 'User-Agent' => 'WeatherWrite/1.0 (' . home_url() . ')', 'Accept' => 'application/json' ] ] ); 77 if ( is_wp_error( $response ) ) { 78 return $response; 79 } 80 81 $code = wp_remote_retrieve_response_code( $response ); 82 $body = wp_remote_retrieve_body( $response ); 76 // Retry logic for improved reliability during slow API responses 77 $max_attempts = 2; 78 $attempt = 0; 79 $response = null; 80 $code = 0; 81 $body = ''; 82 83 while ( $attempt < $max_attempts ) { 84 $attempt++; 85 // Use shorter timeout on first attempt (15s), longer on retry (25s) 86 $timeout = ( $attempt === 1 ) ? 15 : 25; 87 $response = wp_remote_get( $url, [ 'timeout' => $timeout, 'headers' => [ 'User-Agent' => 'WeatherWrite/1.0 (' . home_url() . ')', 'Accept' => 'application/json' ] ] ); 88 89 if ( is_wp_error( $response ) ) { 90 // Network error or timeout - retry once 91 if ( $attempt < $max_attempts ) { 92 error_log( "WeatherWrite: Open-Meteo error on attempt {$attempt}, retrying... Error: " . $response->get_error_message() ); 93 sleep( 2 ); // Wait 2 seconds before retry 94 continue; 95 } 96 // Final attempt failed - return error 97 return $response; 98 } 99 100 $code = wp_remote_retrieve_response_code( $response ); 101 $body = wp_remote_retrieve_body( $response ); 102 103 // Retry on 5xx server errors (503 Service Unavailable, 504 Gateway Timeout, etc.) 104 if ( $code >= 500 && $code < 600 && $attempt < $max_attempts ) { 105 error_log( "WeatherWrite: Open-Meteo HTTP {$code} on attempt {$attempt}, retrying..." ); 106 sleep( 2 ); // Wait 2 seconds before retry 107 continue; 108 } 109 110 // Success or non-retryable error - break out 111 break; 112 } 113 83 114 if ( $code < 200 || $code >= 300 ) { 84 return new WP_Error( 'openmeteo_http_error', 'Weather API error ', [ 'status' => $code, 'body' => $body ] );115 return new WP_Error( 'openmeteo_http_error', 'Weather API error after ' . $attempt . ' attempts', [ 'status' => $code, 'body' => $body ] ); 85 116 } 86 117 -
weather-write/trunk/includes/class-reintent.php
r3385495 r3424471 68 68 ]; 69 69 70 // Retry logic for 504 Gateway Timeouterrors70 // Retry logic for network errors and 5xx server errors 71 71 $max_attempts = 2; 72 72 $attempt = 0; … … 82 82 // Network error - retry once 83 83 if ( $attempt < $max_attempts ) { 84 error_log( "WeatherWrite: ChatGPT network error on attempt {$attempt}, retrying... ");84 error_log( "WeatherWrite: ChatGPT network error on attempt {$attempt}, retrying... Error: " . $resp->get_error_message() ); 85 85 sleep( 2 ); // Wait 2 seconds before retry 86 86 continue; … … 92 92 $body = wp_remote_retrieve_body( $resp ); 93 93 94 // Retry on 504 Gateway Timeout95 if ( $code === 504&& $attempt < $max_attempts ) {96 error_log( "WeatherWrite: ChatGPT 504 timeouton attempt {$attempt}, retrying..." );94 // Retry on all 5xx server errors (500, 502, 503, 504, etc.) 95 if ( $code >= 500 && $code < 600 && $attempt < $max_attempts ) { 96 error_log( "WeatherWrite: ChatGPT HTTP {$code} on attempt {$attempt}, retrying..." ); 97 97 sleep( 2 ); // Wait 2 seconds before retry 98 98 continue; -
weather-write/trunk/readme.txt
r3424052 r3424471 4 4 Requires at least: 6.5 5 5 Tested up to: 6.8 6 Stable tag: 1.3.1 46 Stable tag: 1.3.15 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 87 87 88 88 == Changelog == 89 90 = 1.3.15 = 91 - ENHANCEMENT: Improved Open-Meteo API reliability with smart retry logic 92 - First attempt uses 15-second timeout for fast failure detection 93 - Automatic retry with 25-second timeout on network errors or 5xx server errors 94 - ENHANCEMENT: Enhanced ReIntent API retry logic to handle all 5xx server errors (not just 504) 95 - Both APIs now retry on network errors, timeouts, and server errors 96 - 2-second delay between retry attempts to allow transient issues to resolve 97 - Significantly reduces API failures during peak hours and service disruptions 98 - Better error logging for debugging retry attempts 89 99 90 100 = 1.3.14 = -
weather-write/trunk/weather-write.php
r3424052 r3424471 3 3 * Plugin Name: Weather Write 4 4 * Description: Generate and publish weather-aware posts with summaries, charts, images, alerts, SEO, and more — fully automated or on-demand. 5 * Version: 1.3.1 45 * Version: 1.3.15 6 6 * Author: Mike Freeman - WeatherWrite 7 7 * Plugin URI: https://www.weatherwrite.com/
Note: See TracChangeset
for help on using the changeset viewer.