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
Hi @rubenf @fjørdlek , wanted to follow up on this
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
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}
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:
Hi Alex, yes! But it requires a job id. I am unable to get the new job id after running recompute("bg_0")
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
Thank you, @fjørdlek , I'll wait to hear from you.
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
note that a background job that is frontend js will not generate a job id as it's not running a windmill job
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?
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)
The approach you have is working, but it's not allowing me to call antyhing from a script and wait for it
so your constraint is to use
recompute("bg_0")
instead of observing changes and recompute would not trigger rerunning / creating a new job id?it triggers run, and generate jobid, but the jobid is not accessible within the same script run