Dan
Dan3d ago

Windmill Apps: frontend script helpers : recompute a backend script and wait for new job id

Hi! I was not able to do this. Is there any way to recompute / run backend script from front end code, and wait for the result or for the new job id? (even in async function, I'm still getting a stale job id)
14 Replies
Dan
DanOP2d ago
Hi @rubenf @fjørdlek , wanted to follow up on this
fjørdlek
fjørdlek2d ago
Can you share the code you tried that give you a stale job id? but basically this would be the approach import the windimll client
import { runScriptAsync, waitJob } from 'windmill-client';

// Define the main function
export async function main(path: string): Promise<any> {
const jobId = await runScriptAsync(path, null, { x: 'hello'});
const jobResult = await waitJob(jobId);
return jobResult
}
import { runScriptAsync, waitJob } from 'windmill-client';

// Define the main function
export async function main(path: string): Promise<any> {
const jobId = await runScriptAsync(path, null, { x: 'hello'});
const jobResult = await waitJob(jobId);
return jobResult
}
Dan
DanOP2d ago
Hi Alex, thank you! See the script below. This is a frontend js in App: let job1 = "" let job2 = "" async function runAndWait() { await new Promise(resolve => setTimeout(resolve, 2000)) job1 = bg_0.jobId await new Promise(resolve => setTimeout(resolve, 2000)) await recompute("bg_0") await new Promise(resolve => setTimeout(resolve, 2000)) job2 = bg_0.jobId } await runAndWait() return {job1, job2}
fjørdlek
fjørdlek2d ago
have you tried the frontend helper: waitJob ? https://www.windmill.dev/docs/apps/app-runnable-panel#waitjob
Runnable editor | Windmill
The strength of Windmill's app editor is the ability to connect everything together:
Dan
DanOP2d ago
Hi Alex, yes! But it requires a job id. I am unable to get the new job id after running recompute("bg_0")
fjørdlek
fjørdlek2d ago
ok I think I get it: you have a background runnable, you want to get this job_id and wait for it to complete... sorry misunderstood the original issue. Will test and report back
Dan
DanOP2d ago
Thank you, @fjørdlek , I'll wait to hear from you.
fjørdlek
fjørdlek2d ago
can you try to import this app it works for me: I have two runnables: - bg_0 (backend, bun) that I hook up to a text field - bg_1 (frontend js with waitJob) "values watched: bg_0.jobid) anytime i update the textfield it will run a new job and bg_1 will watch for the result and return it
fjørdlek
fjørdlek2d ago
note that a background job that is frontend js will not generate a job id as it's not running a windmill job
Dan
DanOP2d ago
Thank you, @fjørdlek , this works for me as well. From my frontend code, I want to be able to call an execution of backend runnable, and wait for the result. Does that make sense?
fjørdlek
fjørdlek2d ago
yes, can you then try to use the same approach as in the app I shared? (look at how the two background runnables are implemented / interacting)
Dan
DanOP2d ago
The approach you have is working, but it's not allowing me to call antyhing from a script and wait for it
fjørdlek
fjørdlek2d ago
so your constraint is to use recompute("bg_0") instead of observing changes and recompute would not trigger rerunning / creating a new job id?
Dan
DanOP2d ago
it triggers run, and generate jobid, but the jobid is not accessible within the same script run

Did you find this page helpful?