feat: new deploy queue with live job logs
This commit is contained in:
@@ -36,3 +36,48 @@ export function sleep(timeout: number) {
|
||||
setTimeout(resolve, timeout)
|
||||
})
|
||||
}
|
||||
|
||||
export class JsonResponse extends Response {
|
||||
constructor(data: any) {
|
||||
super(JSON.stringify(data), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class JsonStreamResponse extends Response {
|
||||
constructor(create: (send: (data: any) => void) => () => void | undefined) {
|
||||
let cancelFn: () => void | undefined
|
||||
|
||||
const stream = new ReadableStream({
|
||||
start(controller) {
|
||||
const sendEvent = (data: any) => {
|
||||
controller.enqueue(`data: ${JSON.stringify(data)}\r\n\r\n`)
|
||||
}
|
||||
|
||||
cancelFn = create(sendEvent)
|
||||
},
|
||||
cancel() {
|
||||
cancelFn?.()
|
||||
},
|
||||
})
|
||||
|
||||
super(stream, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Connection': 'keep-alive',
|
||||
'Cache-Control': 'no-cache',
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function createQueryUrl(base: string, options: Record<string, string>) {
|
||||
return `${base}?${Object.entries(options)
|
||||
.map(([k, v]) => k + '=' + encodeURIComponent(v))
|
||||
.join('&')}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user