diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-01-27 07:42:31 -0500 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-01-27 07:42:52 -0500 |
| commit | 95d775d4d8e6c3d3204ad6360ea29fb6dff53a2c (patch) | |
| tree | fdbae61742cff14142fd344f45120551befd6112 /scripts/prebake-node.mjs | |
| parent | b2d1a2eb9b93ddc92938f2a912e01b87b1f65c14 (diff) | |
| download | xesite-95d775d4d8e6c3d3204ad6360ea29fb6dff53a2c.tar.xz xesite-95d775d4d8e6c3d3204ad6360ea29fb6dff53a2c.zip | |
Xeact talk
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'scripts/prebake-node.mjs')
| -rw-r--r-- | scripts/prebake-node.mjs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/prebake-node.mjs b/scripts/prebake-node.mjs new file mode 100644 index 0000000..4a85312 --- /dev/null +++ b/scripts/prebake-node.mjs @@ -0,0 +1,56 @@ +import { execaCommand } from "execa"; + +if (process.argv.length === 2) { + console.error(`usage: node prebake-node.js <path> <video segment count>`); + process.exit(1); +} + +const [_node, _script, basePath, countStr] = process.argv; + +const instances = await (async () => { + try { + const { stdout } = await execaCommand( + "flyctl machines list -a xedn --json --state started | jq [.[].ID]", + { + shell: true, + }, + ); + const instances = JSON.parse(stdout); + return instances; + } catch (error) { + console.error(error); + } +})(); + +for (const i of Array(parseInt(countStr) + 1).keys()) { + try { + const reqs = instances.map((x) => + fetch( + `https://cdn.xeiaso.net/file/christine-static/${basePath}/index${i}.ts`, + { + headers: { + "fly-force-instance": x, + }, + }, + ).then((resp) => { + console.log(`${x}: response get: ${resp.status}`); + return resp; + }) + ); + + const resps = await Promise.all(reqs); + resps.forEach(async (resp) => { + if (resp.status !== 200) { + console.error( + `failure: ${resp.url}: request ID: ${ + resp.headers["fly-request-id"] + }, body: ${await resp.text()}`, + ); + } + + console.log(`ok: ${resp.headers["fly-request-id"]}`); + }); + } catch (e) { + console.error(e); + } +} |
