diff --git a/ingest-image/package-lock.json b/ingest-image/package-lock.json index 487df67..0f90cbb 100644 --- a/ingest-image/package-lock.json +++ b/ingest-image/package-lock.json @@ -18,6 +18,7 @@ "rimraf": "^5.0.0", "sharp": "^0.32.0", "strtime": "^1.1.2", + "undici": "^5.24.0", "uuid": "^9.0.0" }, "devDependencies": { @@ -1824,6 +1825,17 @@ "ieee754": "^1.1.13" } }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -3343,6 +3355,14 @@ "is-arrayish": "^0.3.1" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/streamx": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.1.tgz", @@ -3555,6 +3575,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/undici": { + "version": "5.24.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.24.0.tgz", + "integrity": "sha512-OKlckxBjFl0oXxcj9FU6oB8fDAaiRUq+D8jrFWGmOfI/gIyjk/IeS75LMzgYKUaeHzLUcYvf9bbJGSrUwTfwwQ==", + "dependencies": { + "busboy": "^1.6.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/ingest-image/package.json b/ingest-image/package.json index 2d62f36..72432e1 100644 --- a/ingest-image/package.json +++ b/ingest-image/package.json @@ -21,8 +21,7 @@ "mime-types": "^2.1.35", "rimraf": "^5.0.0", "sharp": "^0.32.0", - "strtime": "^1.1.2", - "uuid": "^9.0.0" + "strtime": "^1.1.2" }, "devDependencies": { "eslint": "^8.33.0", diff --git a/ingest-image/task.js b/ingest-image/task.js index c909a67..ef17e13 100644 --- a/ingest-image/task.js +++ b/ingest-image/task.js @@ -169,7 +169,6 @@ export default class Task { } else { await this.copy_to_prod(md); } - } catch (err) { // backstop for unforeseen errors returned by the API // and errors resizing/copying the image to prod buckets. @@ -368,8 +367,13 @@ export default class Task { async function fetcher(url, body) { console.log('Posting metadata to API', JSON.stringify(body)); + + const controller = new AbortController(); + const id = setTimeout(() => controller.abort(), 10_000); + const res = await fetch(url, { method: 'POST', + signal: controller.signal, headers: { 'Content-Type': 'application/json', 'x-api-key': APIKEY @@ -377,6 +381,8 @@ async function fetcher(url, body) { body: JSON.stringify(body) }); + clearTimeout(id); + if (!res.ok) { const texterr = await res.text(); let jsonerr;