refactor
This commit is contained in:
parent
319902179c
commit
729d401ac3
12 changed files with 77 additions and 32 deletions
15
dist/remote-cache-server/index.js
vendored
15
dist/remote-cache-server/index.js
vendored
|
|
@ -81894,13 +81894,14 @@ const fs = __nccwpck_require__(7147)
|
|||
const server = http.createServer(async (req, res) => {
|
||||
const { method, url } = req
|
||||
const [, , cacheType, sha] = url.split('/')
|
||||
const cacheKey = `setup-bazel-1-remote-cache-${sha}`
|
||||
const filePath = `/tmp/cache-${cacheType}-${sha}`
|
||||
|
||||
if (method === 'GET') {
|
||||
try {
|
||||
const cacheId = await cache.restoreCache([filePath], sha)
|
||||
const cacheId = await cache.restoreCache([filePath], cacheKey)
|
||||
if (!cacheId) {
|
||||
console.log(`Cache miss for ${sha}`)
|
||||
console.log(`Cache miss for ${cacheKey}`)
|
||||
res.writeHead(404)
|
||||
return res.end('Cache miss')
|
||||
}
|
||||
|
|
@ -81908,7 +81909,7 @@ const server = http.createServer(async (req, res) => {
|
|||
res.writeHead(200, { 'Content-Type': 'application/octet-stream' })
|
||||
res.end(data)
|
||||
} catch (error) {
|
||||
console.error(`Error retrieving cache for ${sha}: ${error}`)
|
||||
console.error(`Error retrieving cache for ${cacheKey}: ${error}`)
|
||||
res.writeHead(500)
|
||||
res.end('Internal Server Error')
|
||||
}
|
||||
|
|
@ -81918,12 +81919,12 @@ const server = http.createServer(async (req, res) => {
|
|||
req.on('end', async () => {
|
||||
try {
|
||||
fs.writeFileSync(filePath, Buffer.concat(data))
|
||||
await cache.saveCache([filePath], sha)
|
||||
console.log(`Cache saved for ${sha}`)
|
||||
await cache.saveCache([filePath], cacheKey)
|
||||
console.log(`Cache saved for ${cacheKey}`)
|
||||
res.writeHead(201)
|
||||
res.end('Cache saved')
|
||||
} catch (error) {
|
||||
console.error(`Error saving cache for ${sha}: ${error}`)
|
||||
console.error(`Error saving cache for ${cacheKey}: ${error}`)
|
||||
res.writeHead(500)
|
||||
res.end('Internal Server Error')
|
||||
}
|
||||
|
|
@ -81934,7 +81935,7 @@ const server = http.createServer(async (req, res) => {
|
|||
}
|
||||
})
|
||||
|
||||
const PORT = process.env.PORT || 8080
|
||||
const PORT = process.env.PORT || 9889
|
||||
server.listen(PORT, () => console.log(`Server listening on port ${PORT}`))
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue