Skip to content

Commit aa672b5

Browse files
committed
increase connection timeout
1 parent 73f73d2 commit aa672b5

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

lib/check_urls.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import records from "../_data/catalogs.js";
2+
import { Agent } from "undici";
3+
4+
const TIMEOUT_IN_MS = 20 * 1000;
5+
// connection timeout
6+
// https://stackoverflow.com/a/77319848/358804
7+
const AGENT = new Agent({ connectTimeout: TIMEOUT_IN_MS });
8+
// response timeout
9+
const SIGNAL = AbortSignal.timeout(TIMEOUT_IN_MS);
210

311
const handleError = (url, error) => {
412
const cause = error.cause || {};
@@ -20,12 +28,12 @@ const checkUrl = async (url) => {
2028
"User-Agent": "https://dataportals.org/ bot",
2129
},
2230
redirect: "follow",
23-
signal: AbortSignal.timeout(20 * 1000),
31+
dispatcher: AGENT,
32+
signal: SIGNAL,
2433
});
2534

26-
const status = response.status;
27-
if (status < 200 || status >= 300) {
28-
console.warn(`${url} has status ${status}`);
35+
if (!response.ok) {
36+
console.warn(`${url} has status ${response.status}`);
2937
return false;
3038
}
3139
} catch (error) {

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"dependencies": {
1313
"@11ty/eleventy": "^3.0.0",
1414
"csv-parse": "^5.6.0",
15-
"markdown-it": "^14.1.0"
15+
"markdown-it": "^14.1.0",
16+
"undici": "^7.10.0"
1617
},
1718
"repository": {
1819
"type": "git",

0 commit comments

Comments
 (0)