MCPcopy
hub / github.com/omkarcloud/botasaurus / checkMasterHealth

Function checkMasterHealth

js/botasaurus-server-js/src/api-config.ts:63–98  ·  view source on GitHub ↗

* Check master endpoint health, retrying up to 3 times.

(masterEndpoint: string)

Source from the content-addressed store, hash-verified

61 * Check master endpoint health, retrying up to 3 times.
62 */
63async function checkMasterHealth(masterEndpoint: string) {
64 const MAX_RETRIES = 3;
65 let retryCount = 0;
66 while (retryCount < MAX_RETRIES) {
67 retryCount++;
68 try {
69 const response = await fetch(`${masterEndpoint}/health`, {
70 method: 'GET',
71 signal: AbortSignal.timeout(10000) // 10 second timeout
72 });
73
74 if (!response.ok) {
75 throw new Error(`Health check returned status ${response.status}`);
76 }
77 if (retryCount > 1) {
78 console.debug(`[K8s] Successfully reached master after retry (attempt ${retryCount}/${MAX_RETRIES}): ${masterEndpoint}`);
79 }
80 return true;
81 } catch (error: any) {
82 console.error(error);
83 console.debug(`[K8s] Health check error (attempt ${retryCount}/${MAX_RETRIES}): ${error instanceof Error ? error.message : error} - ${masterEndpoint}`);
84 if (retryCount < MAX_RETRIES) {
85 // Wait briefly before retrying
86 await sleep(3);
87 continue;
88 }
89 }
90 }
91
92 console.error(`[K8s] Failed to reach master after ${MAX_RETRIES} attempts: ${masterEndpoint}`);
93 if (!ApiConfig.isMasterNode()) {
94 // If not master node, exit the process
95 process.exit(1);
96 }
97 return false;
98}
99
100
101function addCorsHeaders(reply: any) {

Callers 1

enableKubernetesMethod · 0.85

Calls 2

sleepFunction · 0.90
isMasterNodeMethod · 0.80

Tested by

no test coverage detected