Function: performPingCheckWithRetry()
performPingCheckWithRetry(
host
:string
,timeout
:number
,maxRetries
:number
):Promise
<MonitorCheckResult
>
Defined in: electron/services/monitoring/utils/pingRetry.ts:172
Performs a ping connectivity check with retry logic and exponential backoff.
Parameters
host
string
Target hostname or IP address to ping
timeout
number
Maximum time to wait for each ping attempt in milliseconds
maxRetries
number
Number of additional retry attempts after initial failure (0 = try once only)
Returns
Promise resolving to MonitorCheckResult with ping status, timing, and details
Remarks
This function wraps performSinglePingCheck with retry logic using
withOperationalHooks. It attempts to ping the specified host, retrying
on failure up to maxRetries
times (for a total of maxRetries
+ 1
attempts). Exponential backoff is applied between attempts.
Process flow:
- Validates input parameters
- Performs initial ping attempt
- On failure, retries with exponential backoff
- Returns standardized result or error
Debug logging is enabled in development mode to aid troubleshooting. If all attempts fail, returns a standardized error result via handlePingCheckError.
Example
// Try once, no retries
const result = await performPingCheckWithRetry("example.com", 5000, 0);
// Try 4 times total (1 initial + 3 retries) with 3-second timeout
const result = await performPingCheckWithRetry("google.com", 3000, 3);
if (result.status === "up") {
console.log(`Ping successful: ${result.responseTime}ms`);
} else {
console.log(`Ping failed: ${result.error}`);
}
See
- withOperationalHooks - Retry logic implementation
- performSinglePingCheck - Single ping attempt function
- handlePingCheckError - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Error handling utility