Skip to content

Commit

Permalink
Alernative Abort Approach
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Sep 18, 2023
1 parent dc95221 commit 95753ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 1 addition & 3 deletions ingest-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"mime-types": "^2.1.35",
"rimraf": "^5.0.0",
"sharp": "^0.32.0",
"strtime": "^1.1.2",
"undici": "^5.24.0",
"uuid": "^9.0.0"
"strtime": "^1.1.2"
},
"devDependencies": {
"eslint": "^8.33.0",
Expand Down
14 changes: 7 additions & 7 deletions ingest-image/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ import { createHash } from 'node:crypto';
import { pipeline } from 'node:stream/promises';
import fs from 'node:fs';
import fsp from 'node:fs/promises';
import { fetch, setGlobalDispatcher, Agent } from 'undici';

setGlobalDispatcher(new Agent({
connect: {
timeout: 10_000
}
}));

const region = process.env.AWS_DEFAULT_REGION || 'us-west-2';

Expand Down Expand Up @@ -374,15 +367,22 @@ 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
},
body: JSON.stringify(body)
});

clearTimeout(id);

if (!res.ok) {
const texterr = await res.text();
let jsonerr;
Expand Down

0 comments on commit 95753ff

Please sign in to comment.