Good day, I am currently working on building a custom javascript code execution platform using Deno Workers. Additionally, I have implemented an Oak web server to manage requests for script modifications and their compilation and execution.
An issue arises when I request the re-execution of a modified script (e.g. console.log()) after making changes. Deno executes the Worker with the old code until I restart the Oak server, causing delays in reflecting the updates.
export class Runner {
private task: Task;
constructor(task: Task) {
this.task = task;
}
async run() {
new Worker(
new URL(await joinPath(`tasks/${this.task.id}/output.js`), import.meta.url).href,
{ type: "module" }
);
}
}
The Runner class manages the initialization of the Worker, creating a new instance of Runner for each execution request, hence a new Worker instance as well.
// oak router
router.get("/api/tasks/:id/run", async ctx => {
const id: any = ctx.params.id;
if (!id) ctx.throw(500);
const task: Task = await get(id);
const compiler: Compiler = new Compiler(task);
const runner: Runner = new Runner(task);
await compiler.compile();
await runner.run();
ctx.response.body = 'ok';
});
This function processes the request by instantiating the Runner class.
Thank you very much for your attention.