Skip to content

Commit ece3dda

Browse files
committed
reduce CI server load
1 parent 8ab7d46 commit ece3dda

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

src/scripts/link-check/linkcheck.ts

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const BASE_URL = "http://localhost:4321"
1313
const TEMP_DIR = `${cwd()}/temp`
1414
const LOG_FILE = `${TEMP_DIR}/link-checker.log`
1515

16-
const LINK_CHUNK_SIZE = 300
16+
const LINK_CHUNK_SIZE = 150
1717

1818
// ================================
1919
// HELPER FUNCTIONS
@@ -42,14 +42,36 @@ function displayLogFile() {
4242

4343
/**
4444
* Wait for the dev server to be "ready" by checking for a 2xx status on BASE_URL.
45+
* Uses multiple checks to ensure server stability.
4546
*/
4647
async function waitForServerReadiness(url: string, attempts = 20) {
4748
for (let i = 1; i <= attempts; i++) {
4849
try {
4950
const response = await fetch(url)
5051
if (response.ok) {
51-
console.log(`Server is ready at ${url}`)
52-
return
52+
// Server responded, but few more checks to ensure stability
53+
console.log(`Server responded on attempt ${i}, verifying stability...`)
54+
55+
let stableChecks = 0
56+
for (let j = 0; j < 3; j++) {
57+
await new Promise((resolve) => setTimeout(resolve, 2000))
58+
try {
59+
const checkResponse = await fetch(url)
60+
if (checkResponse.ok) {
61+
stableChecks++
62+
}
63+
} catch {
64+
// Stability check failed
65+
break
66+
}
67+
}
68+
69+
if (stableChecks === 3) {
70+
console.log(`Server is ready and stable at ${url}`)
71+
return
72+
} else {
73+
console.log(`Server not yet stable, continuing checks...`)
74+
}
5375
}
5476
} catch {
5577
// Connection error or not ready yet
@@ -238,8 +260,6 @@ async function main() {
238260
// 4) Wait for readiness
239261
try {
240262
await waitForServerReadiness(BASE_URL, 30) // Wait up to 30 attempts
241-
console.log("Server ready, waiting additional 10 seconds for all pages to be available...")
242-
await new Promise((resolve) => setTimeout(resolve, 10000))
243263
} catch (err) {
244264
console.error("Server did not become ready in time.", err)
245265
exit(1)
@@ -249,22 +269,29 @@ async function main() {
249269
const chunkFiles = await processSiteMap(mode)
250270
console.log(`Created ${chunkFiles.length} chunk files.`)
251271

252-
// 6) Run link check on each chunk in parallel, collecting any failures
253-
const checkPromises = chunkFiles.map((chunkFile, index) => {
272+
// 6) Run link check on each chunk sequentially to reduce CI resource pressure
273+
const results: { chunkNumber: number; failed: boolean }[] = []
274+
275+
for (let index = 0; index < chunkFiles.length; index++) {
276+
const chunkFile = chunkFiles[index]
254277
const chunkNumber = index + 1
255278
console.log(`\n>>> Checking chunk ${chunkNumber} of ${chunkFiles.length}: ${chunkFile}\n`)
256279

257-
return checkChunkFile(chunkFile, mode).then((code) => {
258-
if (code !== 0) {
259-
console.error(`Link checker failed on chunk ${chunkNumber} (exit code: ${code})`)
260-
// We'll store chunkNumber with the failure
261-
return { chunkNumber, failed: true }
262-
}
263-
return { chunkNumber, failed: false }
264-
})
265-
})
280+
const code = await checkChunkFile(chunkFile, mode)
281+
if (code !== 0) {
282+
console.error(`Link checker failed on chunk ${chunkNumber} (exit code: ${code})`)
283+
results.push({ chunkNumber, failed: true })
284+
} else {
285+
results.push({ chunkNumber, failed: false })
286+
}
287+
288+
// Add a small delay between chunks to reduce server pressure
289+
if (index < chunkFiles.length - 1) {
290+
console.log("Waiting 2 seconds before next chunk...")
291+
await new Promise((resolve) => setTimeout(resolve, 2000))
292+
}
293+
}
266294

267-
const results = await Promise.all(checkPromises)
268295
const failedChunks = results.filter((r) => r.failed).map((r) => r.chunkNumber)
269296

270297
// 7) If any chunks failed, exit with error after we've checked them all

0 commit comments

Comments
 (0)