Files
ghaymah-dns-net-sec-tests/scripts/wait_for_gateway_sync.js
T

41 lines
1.5 KiB
JavaScript

const { getAuth } = require('./auth_manager');
async function main() {
const td = await getAuth();
console.log('Monitoring soc-gateway build and deployment...');
const start = Date.now();
while (Date.now() - start < 180000) {
const res = await fetch('https://graphql.ghaymah.systems/v1/graphql', {
method: 'POST',
headers: { 'Authorization': 'Bearer ' + td.token, 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `query {
ghaymah_cloud_resources_by_pk(id: "3d5666fe-95db-4e73-b6b2-dd0e41fca7f6") {
id status message
}
}`
})
});
const d = await res.json();
const r = d.data?.ghaymah_cloud_resources_by_pk;
const elapsed = Math.round((Date.now() - start) / 1000);
console.log(`[+${elapsed}s] status: ${r?.status} | message: ${r?.message}`);
if (r?.status === 'synced') {
console.log('Build completed! Probing URL: https://soc-gateway-28cd1dc4e034.hosted.ghaymah.systems/');
const test = await fetch('https://soc-gateway-28cd1dc4e034.hosted.ghaymah.systems/');
console.log('HTTP Status:', test.status);
const text = await test.text();
console.log('Title:', text.match(/<title>([^<]+)<\/title>/)?.[1]);
break;
}
if (r?.status === 'failed' || r?.status === 'backoff') {
console.log('Error occurred:', r?.status, r?.message);
break;
}
await new Promise(r => setTimeout(r, 6000));
}
}
main().catch(console.error);