Skip to content

Commit

Permalink
Use trunk indicator to prevent loader threads bomb
Browse files Browse the repository at this point in the history
  • Loading branch information
Leslie-Wong-H committed Jul 18, 2023
1 parent 8dfecea commit 90bd309
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/worker/loaded.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export default async (req, res) => {
const { imdbID, filename } = req.params;
console.log(`Loaded ${imdbID}/${filename}`);
await knex(TRACE_ALGO).where("path", `${imdbID}/${filename}`).update({ status: "LOADED" });
await sendWorkerJobs(req.app.locals.knex, req.app.locals.workerPool);
if (req.headers["x-trunk-load"] === "true") {
await sendWorkerJobs(req.app.locals.knex, req.app.locals.workerPool);
}
res.sendStatus(204);

if (TELEGRAM_ID && TELEGRAM_URL) {
Expand Down
6 changes: 5 additions & 1 deletion src/worker/send-worker-jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ const lookForLoadJobs = async (knex, workerPool, ws) => {
selectedCore = selectCore.next().value;
}
console.log(`Loading ${file} to ${selectedCore}`);
ws.send(JSON.stringify({ file, core: selectedCore }));
if (i === 0) {
ws.send(JSON.stringify({ trunk: "true", file, core: selectedCore }));
} else {
ws.send(JSON.stringify({ trunk: "false", file, core: selectedCore }));
}
}
} else {
workerPool.set(ws, { status: "READY", type: "load", file: "" });
Expand Down

0 comments on commit 90bd309

Please sign in to comment.