-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: clean up pipeline with generic split, improved fetch, error…
… reporting
- Loading branch information
Showing
5 changed files
with
101 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Transform } from "node:stream"; | ||
import { Entity } from "./entity"; | ||
|
||
export const fetcher = new Transform({ | ||
objectMode: true, | ||
async transform( | ||
{ entity, request }: { entity: Entity; request: Request }, | ||
_, | ||
callback | ||
) { | ||
const start = Date.now(); | ||
|
||
let error; | ||
let data; | ||
|
||
try { | ||
const response = await fetch(request); | ||
data = { entity, response, responseTime: Date.now() - start }; | ||
} catch (err) { | ||
error = err instanceof Error ? err : new Error(String(err)); | ||
} | ||
|
||
callback(error, data); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters