feat: new deploy queue with live job logs

This commit is contained in:
2024-03-11 02:02:56 +01:00
parent 3083dc5f18
commit ad49ce171d
14 changed files with 623 additions and 176 deletions
+45
View File
@@ -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('&')}`
}