Skip to content

Commit b9f76fa

Browse files
committed
feat: update docker images to v0.0.19 and enhance DB update logic with timeout and retries in youtube-worker
1 parent 18e20c4 commit b9f76fa

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
server:
3-
image: skeptrune/jukebox-server:v0.0.18
3+
image: skeptrune/jukebox-server:v0.0.19
44
ports:
55
- "${SERVER_PORT}:${SERVER_INTERNAL_PORT}"
66
env_file:
@@ -40,7 +40,7 @@ services:
4040
window: 60s
4141

4242
worker1:
43-
image: skeptrune/jukebox-worker:v0.0.18
43+
image: skeptrune/jukebox-worker:v0.0.19
4444
ports:
4545
- "${WORKER1_PORT}:${WORKER1_INTERNAL_PORT}"
4646
env_file:
@@ -74,7 +74,7 @@ services:
7474
retries: 3
7575

7676
worker2:
77-
image: skeptrune/jukebox-worker:v0.0.18
77+
image: skeptrune/jukebox-worker:v0.0.19
7878
ports:
7979
- "${WORKER2_PORT}:${WORKER2_INTERNAL_PORT}"
8080
env_file:
@@ -108,7 +108,7 @@ services:
108108
retries: 3
109109

110110
worker3:
111-
image: skeptrune/jukebox-worker:v0.0.18
111+
image: skeptrune/jukebox-worker:v0.0.19
112112
ports:
113113
- "${WORKER3_PORT}:${WORKER3_INTERNAL_PORT}"
114114
env_file:
@@ -142,7 +142,7 @@ services:
142142
retries: 3
143143

144144
frontend:
145-
image: skeptrune/jukebox-spa:v0.0.18
145+
image: skeptrune/jukebox-spa:v0.0.19
146146
env_file:
147147
- .env
148148
ports:

server/src/youtube-worker.ts

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,46 @@ async function workerLoop() {
344344
});
345345
});
346346
await uploadPromise;
347-
// Mark as completed
348-
await db
349-
.updateTable("song_youtube_status")
350-
.set({
351-
status: "completed",
352-
updated_at: new Date().toISOString(),
353-
error_message: null,
354-
})
355-
.where("youtube_id", "=", youtube_id)
356-
.where("status", "=", "processing")
357-
.execute();
358347
console.log(
359-
`\x1b[32mUploaded ${youtube_id} to S3 as ${s3Key}\x1b[0m`
348+
`\x1b[32mSuccessfully uploaded ${youtube_id} to S3 as ${s3Key}\x1b[0m`
349+
);
350+
// Add a timeout of 5s with up to 5 retries for DB update
351+
const updateWithTimeout = async (retries = 5): Promise<void> => {
352+
for (let attempt = 1; attempt <= retries; attempt++) {
353+
try {
354+
await Promise.race([
355+
db
356+
.updateTable("song_youtube_status")
357+
.set({
358+
status: "completed",
359+
updated_at: new Date().toISOString(),
360+
error_message: null,
361+
})
362+
.where("youtube_id", "=", youtube_id)
363+
.where("status", "=", "processing")
364+
.execute(),
365+
new Promise((_, reject) =>
366+
setTimeout(
367+
() => reject(new Error("DB update timeout after 2s")),
368+
2000
369+
)
370+
),
371+
]);
372+
return; // Success
373+
} catch (err) {
374+
if (attempt === retries) {
375+
throw err;
376+
}
377+
console.error(
378+
`DB update attempt ${attempt} failed for ${youtube_id}, retrying...`,
379+
err
380+
);
381+
}
382+
}
383+
};
384+
await updateWithTimeout();
385+
console.log(
386+
`\x1b[32mMarked ${youtube_id} as completed in database\x1b[0m`
360387
);
361388
await sendSuccessEmail(youtube_id);
362389
return;

0 commit comments

Comments
 (0)