Skip to content

Commit

Permalink
Handle unexpected endpoint closures in script (#310)
Browse files Browse the repository at this point in the history
* handle unexpected endpoint closures

* add changeset
  • Loading branch information
mmaurello authored Jul 19, 2024
1 parent 0f9b574 commit 301964f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-cobras-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@moonbeam-network/xcm-config': patch
---

Remove duplicated nodle endpoint
1 change: 0 additions & 1 deletion packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,6 @@ export const nodle = new Parachain({
parachainId: 2026,
ss58Format: 37,
ws: [
'wss://nodle-rpc.dwellir.com',
'wss://nodle-rpc.dwellir.com',
'wss://nodle-parachain.api.onfinality.io/public-ws',
],
Expand Down
17 changes: 15 additions & 2 deletions scripts/check-websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function checkIsWebSocketAlive({
return new Promise((resolve, reject) => {
const ws = new WebSocket(endpoint);

console.log(`Connecting to ${chainKey} endpoint ${endpoint}`);
ws.on('error', (error: Error) => {
console.error(
`${chainKey} WebSocket connection to ${endpoint} failed`,
Expand All @@ -41,6 +42,15 @@ function checkIsWebSocketAlive({
ws.close();
resolve(true);
});

ws.on('close', (code: number, reason: string) => {
if (code !== 1000) {
console.log(
`${chainKey} WebSocket connection to ${endpoint} closed with code ${code} and reason: ${reason}`,
);
resolve(false);
}
});
});
}

Expand Down Expand Up @@ -109,9 +119,12 @@ function countChainKeys(endpoints: ChainEndpoint[]): Record<string, number> {

async function sendNotification(
chainsToReview: string[],
failingEndpoints: ChainEndpoint[],
webhookUrl: string | undefined,
) {
const text = `All the websocket endpoints available to the XCM integrations in the dapp for \`${chainsToReview.join(', ')}\` are not working, please review them`;
const text = `All the websocket endpoints available to the XCM integrations in the dapp for \`${chainsToReview.join(', ')}\` are not working, please review them\nFailing endpoints: \n${failingEndpoints
.map((endpoint) => `${endpoint.chainKey}: ${endpoint.ws}`)
.join('\n')}`;
console.log(text);

if (webhookUrl) {
Expand Down Expand Up @@ -155,7 +168,7 @@ async function main() {
});

if (chainsToReview.length) {
await sendNotification(chainsToReview, webhookUrl);
await sendNotification(chainsToReview, failingEndpoints, webhookUrl);
}
} else {
console.log('All checked endpoints are working.');
Expand Down

0 comments on commit 301964f

Please sign in to comment.