Slide 51
Slide 51 text
Uploading - worker waits for chunks
queue.on('connect', () => {
http.listen(port, () => { console.log(`=== [${workerName}] listening on ${port}… ===` ) })
})
queue.on('message', (attrs) => {
let route = `/api/${workerName}/upload/${attrs.id}`
queue.transmit('ready', Object.assign({ route: route }, attrs))
http.post(`/upload/${attrs.id}`, (req, res) => {
let upload = new Upload(attrs.id, req.headers)
queue.transmit('begin', attrs)
upload.on('file:end', () => {
queue.transmit('done', attrs)
res.writeHead(200, { 'Connection': 'close' })
res.end("That's all folks!")
})
return req.pipe(upload)
})
})
worker listens for particular URL
writes file/chunk to disk, could be stored in memory