fix: waitJob getJob and streamJob in raw apps (#7901)
* fix: waitJob getJob and streamJob in raw apps * nits * use latest ui builder * fix --------- Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
This commit is contained in:
@@ -20,7 +20,7 @@ console.log('Running postinstall for root project');
|
||||
|
||||
import { x } from 'tar'
|
||||
|
||||
const tarUrl = 'https://pub-06154ed168a24e73a86ab84db6bf15d8.r2.dev/ui_builder-1fcd9b7.tar.gz'
|
||||
const tarUrl = 'https://pub-06154ed168a24e73a86ab84db6bf15d8.r2.dev/ui_builder-0e5c66f.tar.gz'
|
||||
const outputTarPath = path.join(process.cwd(), 'ui_builder.tar.gz')
|
||||
const extractTo = path.join(process.cwd(), 'static/ui_builder/')
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
result = e
|
||||
}
|
||||
|
||||
if (event.data.type == 'backend') {
|
||||
if (event.data.type == 'backend' || event.data.type == 'waitJob') {
|
||||
respond({ result, error })
|
||||
}
|
||||
if (editor) {
|
||||
@@ -134,6 +134,7 @@
|
||||
const reqId = data.reqId
|
||||
const params = new URLSearchParams()
|
||||
params.set('fast', 'true')
|
||||
params.set('only_result', 'true')
|
||||
|
||||
const sseUrl = `/api/w/${workspace}/jobs_u/getupdate_sse/${jobId}?${params.toString()}`
|
||||
const eventSource = new EventSource(sseUrl)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
let reqs: Record<string, any> = {}
|
||||
|
||||
function doRequest(type: string, o: object) {
|
||||
function doRequest(type: string, o: object, extra?: object) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reqId = Math.random().toString(36)
|
||||
reqs[reqId] = { resolve, reject }
|
||||
parent.postMessage({ ...o, type, reqId }, '*')
|
||||
reqs[reqId] = { resolve, reject, ...extra }
|
||||
const req = { ...o, type, reqId }
|
||||
parent.postMessage(req, '*')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,15 +50,11 @@ export function streamJob(
|
||||
jobId: string,
|
||||
onUpdate?: (data: { new_result_stream?: string; stream_offset?: number }) => void
|
||||
): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reqId = Math.random().toString(36)
|
||||
reqs[reqId] = { resolve, reject, onUpdate }
|
||||
parent.postMessage({ jobId, type: 'streamJob', reqId }, '*')
|
||||
})
|
||||
return doRequest('streamJob', { jobId }, { onUpdate })
|
||||
}
|
||||
|
||||
window.addEventListener('message', (e) => {
|
||||
if (e.data.type == 'streamJobUpdate') {
|
||||
if (e.data.type === 'streamJobUpdate') {
|
||||
// Handle streaming update
|
||||
let job = reqs[e.data.reqId]
|
||||
if (job && job.onUpdate) {
|
||||
@@ -66,7 +63,7 @@ window.addEventListener('message', (e) => {
|
||||
stream_offset: e.data.stream_offset
|
||||
})
|
||||
}
|
||||
} else if (e.data.type == 'streamJobRes') {
|
||||
} else if (e.data.type === 'streamJobRes') {
|
||||
// Handle stream completion
|
||||
let job = reqs[e.data.reqId]
|
||||
if (job) {
|
||||
@@ -77,7 +74,12 @@ window.addEventListener('message', (e) => {
|
||||
}
|
||||
delete reqs[e.data.reqId]
|
||||
}
|
||||
} else if (e.data.type == 'backendRes' || e.data.type == 'backendAsyncRes') {
|
||||
} else if (
|
||||
e.data.type === 'backendRes' ||
|
||||
e.data.type === 'backendAsyncRes' ||
|
||||
e.data.type === 'waitJobRes' ||
|
||||
e.data.type === 'getJobRes'
|
||||
) {
|
||||
console.log('Message from parent backend', e.data)
|
||||
let job = reqs[e.data.reqId]
|
||||
if (job) {
|
||||
@@ -87,9 +89,9 @@ window.addEventListener('message', (e) => {
|
||||
} else {
|
||||
job.resolve(result)
|
||||
}
|
||||
delete reqs[e.data.reqId]
|
||||
} else {
|
||||
console.error('No job found for', e.data.reqId)
|
||||
}
|
||||
delete reqs[e.data.reqId]
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user