Ways to prevent Deno Workers from using cached source code

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.

Answer №1

An issue has been raised regarding this on GitHub. It is expected that the cache will be refreshed in the future to accommodate dynamic loads.

For a temporary solution, one can include a query string in the URL and update it with each call to new Worker.

let v = 0;
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?v=${v++}`), import.meta.url).href,
            { type: "module" }
        );
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging async/await within a React functional component

Just getting started with React for a new project and facing challenges incorporating async/await functionality into one of my components. I've created an asynchronous function called fetchKey to retrieve an access key from an API served via AWS API ...

What steps should I take to address a situation in which a Protractor test becomes stuck indefinitely?

I've encountered an issue with a test case that was previously running successfully but is now getting stuck indefinitely during execution. This problem occurs each time the test attempts to click on a specific element, causing the test to hang withou ...

Code for object creation, inheritance, and initialization

In the code snippet below, a class is defined for managing input events such as mouse, touch, and pointer: // base.js export default () => { return { el: undefined, event: undefined, handler(ev) { console.log('default handler&a ...

Develop a prototype function in ES6/ESNext with a distinct scope (avoid using an inline function)

Consider the following example: class Car { constructor(name) { this.kind = 'Car'; this.name = name; } printName() { console.log('this.name'); } } My goal is to define printName using a differe ...

Javascript continues to conceal my web background without my permission

After loading my webpage, I click on a link and the expected javascript runs as planned. However, once it completes and presents the results, the page goes blank to a white screen displaying only the outcomes. My goal is to have these results showcased o ...

Engaging with Electron through an HTML file

Forgive my lack of experience, but I'm diving into the world of Electron and feeling a bit overwhelmed. Here's a snapshot of what I've got so far in my project: package.json: ... "main": "main.js", "scripts": { "start": "electron ." } . ...

When using Rspec and Capybara, utilizing jQuery to set focus on an element may not apply the `:focus` CSS as expected

I have implemented jump links for blind and keyboard users on my website, but I've hidden them off-screen visually. When these links gain focus, they are moved into the viewport. Trying to test this behavior using RSpec and Capybara has been unsucces ...

How to implement automatic scrolling to the bottom of a div in React

Currently facing an issue in React: I am looking to implement auto-scroll functionality when the page loads, so it scrolls to the bottom of the messages box. Here is my current code snippet: import Title from "components/seo/Title"; import { u ...

Generating Angular2 CLI components with Angular-Meteor integration

Exploring Angular2 CLI and Meteor has been an interesting journey for me. One thing I've noticed is that when I create a component using Angular2 CLI, integrating it into another module is as simple as including it in the declarations array of that mo ...

Incorporating Javascript into HTML

I have developed a script to randomly change the size of an element, but I am struggling to understand how to incorporate it using HTML or iframe code for randomization. <script type="text/javascript"> var banner1 = ["728", "90"]; var banne ...

Exploring nested JavaScript attributes using a personalized, dynamic approach

When working with this JavaScript object, the goal is to access its nested properties dynamically using a method that begins with 'get' followed by a CamelCased attribute name (provided that the attribute is defined in the initial object). While ...

Give Jquery a quick breather

My goal is to have my program pause for 3 seconds before continuing with the rest of the code. I've been researching online, but all I can find are methods that delay specific lines of code, which is not what I need. What I would like to achieve look ...

What is the best way to organize objects based on their timestamps?

I am faced with the task of merging two arrays of objects into a single array based on their timestamps. One array contains exact second timestamps, while the other consists of hourly ranges. My goal is to incorporate the 'humidity' values from t ...

The specified column `EventChart.åå` is not found within the existing database

I've been developing a dashboard application using Prisma, Next.js, and supabase. Recently, I encountered an issue when making a GET request. Prisma throws an error mentioning a column EventChart.åå, with a strange alphabet "åå" that I haven&apos ...

Tips for Utilizing Both getElementByID and getElementByTagName Functions in JavaScript

Hi! I'm a beginner in JavaScript and I've managed to retrieve some data using getElementById. Now, I want to extract a specific part using getElementsByTagName. document.getElementById('titleUserReviewsTeaser').innerHTML; " < ...

Transmitting checkbox selections using Ajax

Here is the original code that I have written. It attempts to post the value of an input for each checked checkbox. <tbody class="myFormSaldo"> <tr> <td> <input name="checkbox['.$i.']" type="chec ...

Transforming a string into JSON with proper sanitization

When web scraping, the website returns a string like this on get request: jQuery18305426675335038453_1429531451051({"d":[{"__metadata":"cool"}]}) The complete code snippet is provided below: var baseUrl = "http://SOMEURL.COM?spatialFilter=nearby(52.4795 ...

Guide to positioning a THREE.js plane onto the exterior of a spherical object

Just starting out with Threejs and 3D graphics. I'm interested in learning how to position a plane of any dimensions on the surface of a sphere. Here's an example image of what I'm aiming for: example image ...

What could be the reason for the malfunction of this AngularJS data binding feature?

I am trying to create an angularjs filter that outputs HTML, similar to what is discussed in the link, but I am encountering issues. In my HTML code, I have: <ul> <li ng-repeat="book in books | filter:query"> {{book.title}} ...

JQuery running into issues with proper appending

I am currently in the process of loading XML data using the JQuery.load function, and so far everything is going smoothly. The XML is successfully being loaded and inserted into the DOM, which is exactly what I intended. However, my next step involves iter ...