Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tasks #138

Open
avillega opened this issue Aug 15, 2024 · 5 comments
Open

Tasks #138

avillega opened this issue Aug 15, 2024 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@avillega
Copy link
Contributor

avillega commented Aug 15, 2024

Both the SDK and the Resonate server are converging in what we now call tasks.
There are two types of tasks that represent the events of the global event loop,
Resume and Invoke.

Resume event signals a Resonate node that a promise the node was awaiting on has
been completed and the node can resume work where it left off.

Invoke event signal a Resonate node to invoke a function in its local execution
context and report back its results.

Considerations

  • It is necessary to have a generic mechanism to accept task in the SDK, task could
    come as an http request, messages in distributed queue system like SQS or be polled
    by the SDK itself from the server.
  • We should allow users of the resonate SDK to implement their own tasks sources in a
    way that is compatible with the rest of the Resonate architecture like the server
    communication.
  • We need a local tasks source to be able to use the Resonate SDK without a server
    running.
@avillega avillega added the enhancement New feature or request label Aug 15, 2024
@avillega avillega added this to the 2024-Q4 milestone Aug 15, 2024
@jamesgibson14
Copy link

I am very interested in using SDK-ts with a distributed network, I'd love to help you test things out here, I'm just not sure where to start. I would like to use the SDK in Bun, Nodejs, browsers and web workers. (I don't have a resonate server running )

@avillega
Copy link
Contributor Author

Hey James, you can take a look at some of the examples, currently the sdk works both with Nodejs and Bun (Probably Deno too, he haven't tested out) but does not work in the Browser. You can definitely use the sdk without a server, said that, spinning out a server should be very simple, You can follow the instructions here https://docs.resonatehq.io/resonate/overview

More info about the SDK: https://docs.resonatehq.io/sdks/typescript

@jamesgibson14
Copy link

Actually it work fine in Chrome at least, paste this in the console:

const { Resonate, Context } = await import('https://esm.run/@resonatehq/[email protected]')
async function downloadAndSummarize(context, url) {
  console.log('downloadAndSummarize: main function-')
    // Download the content from the provided URL
    let content = await context.run(download, url);

    // Summarize the downloaded content
    let summary = await context.run(summarize, content);

    // Return the summary of the content
    return summary;
}

async function download(context, url) {
  console.log('download: function-')

    return new Promise((resolve, reject) => {
        setTimeout(() => {
            if (Math.random() < 0.95) { // 10% chance to fail
              console.log('oops, download failed!')
                reject("download failed");
            } else {
                resolve("This is the text of the page");
            }
        }, 2500);
    })
}

async function summarize(context, text) {
    console.log('summarize: function-')

    return new Promise((resolve, reject) => {
        setTimeout(() => {
            if (Math.random() < 0.85) { // 10% chance to fail
                reject("summarize failed");
            } else {
                resolve("This is a summary of the text");
            }
        }, 2500);
    });
}
const resonate = new Resonate();
// resonate.start();
resonate.register("downloadAndSummarize", 
  downloadAndSummarize, 
  { timeout: 120000 }
);
resonate.start()
console.log('running runDownloadAndSummarize', this.resonate)

let summary = await resonate.run("downloadAndSummarize", /* id */ `summarize-abc`, /* param */ 'abc').catch(console.error);
console.log('summary', summary )

@jamesgibson14
Copy link

jamesgibson14 commented Aug 15, 2024

My idea is to implement a RemoteStore to pass to SDK that connects with websockets to a distributed network of.
Maybe I'm way off base, but it seems like it has to do with this issue "Tasks"

@avillega
Copy link
Contributor Author

Depending on what you want Resonate to do for you it might or might not have to do with this issue. You can currently implement your own store. how ever the Resonate server does not support web sockets. To talk between different Resonate nodes Tasks might be the solutions, we are still in design phase for it, but as of now, we will still go through the server, but probably in a more generic way than just http.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants