Code RoomBackground task errors unobserved
MediumPrep Room Coding #1949

Background task errors unobserved

Code reviewCode quality & reviewMid–Senior~18 min

Review this JavaScript request handler that returns immediately and does the slow reindex work in the background.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 18 min
Mark a line and say what kind of problem it is.0 findings
1async function reindex(docId) {
2 const doc = await store.fetch(docId); // may reject
3 await searchClient.index(doc); // may reject / time out
4}
5 
6app.post("/reindex", (req, res) => {
7 const { docId } = req.body;
8 if (!docId) {
9 return res.status(400).json({ error: "docId required" });
10 }
11 res.status(202).json({ status: "queued" });
12 reindex(docId).then(() => {
13 metrics.inc("reindex.ok");
14 });
15});
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.