8000 wait for server by paulr34 · Pull Request #1588 · project-chip/zap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

wait for server #1588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions src-electron/ide-integration/studio-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ function wsApiUrl(api, path) {
return wsLocalhost + studioHttpPort + api + path
}

/**
* Retry connecting to the Studio server until it is ready.
* @param {string} url - The URL to connect to.
* @param {number} retries - Number of retry attempts.
* @param {number} delay - Delay between retries in milliseconds.
* @returns {Promise} - Resolves when the connection is successful, rejects if it fails.
*/
async function waitForServer(url, retries = 5, delay = 2000) {
for (let attempt = 1; attempt <= retries; attempt++) {
try {
let response = await axios.get(url)
if (response.status === 200) {
return response // Server is ready
}
} catch (err) {
env.logWarning(`Attempt ${attempt} failed: ${err.message}`)
if (attempt === retries) {
throw new Error(
`Failed to connect to Studio server at ${url} after ${retries} attempts.`
)
}
}
await new Promise((resolve) => setTimeout(resolve, delay)) // Wait before retrying
}
}
/**
* Send HTTP GET request to Studio Jetty server for project information.
* @param {} db
Expand All @@ -151,16 +176,14 @@ async function getProjectInfo(db, sessionId) {
if (studioIntegration && !isUserDisabled) {
let path = restApiUrl(StudioRestAPI.GetProjectInfo, project)
env.logDebug(`StudioUC(${name}): GET: ${path}`)
return axios
.get(path)
.then((resp) => {
env.logDebug(`StudioUC(${name}): RESP: ${resp.status}`)
return resp
})
.catch((err) => {
env.logWarning(`StudioUC(${name}): ERR: ${err.message}`)
return { data: [] }
})
try {
let response = await waitForServer(path) // Wait for the server to be ready
env.logDebug(`StudioUC(${name}): RESP: ${response.status}`)
return response
} catch (err) {
env.logWarning(`StudioUC(${name}): ERR: ${err.message}`)
return { data: [] }
}
} else {
if (!isUserDisabled)
env.logWarning(`StudioUC(${name}): Studio integration is now enabled!`)
Expand Down
0