Skip to content

Commit

Permalink
Create a new array to process multiple files at once
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Jun 25, 2023
1 parent ebc8c67 commit 3e8583f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,34 @@ Threads.parentPort.on('message', async (Message: string) => {
${ChangedFiles.join('\n - ').replace(/^/, ' - ')}
`)

// Set new array by splitting with each of the 20 items.
var SplittedChangedFiles:Array<string[]> = new Array(Math.ceil(ChangedFiles.length / 20))
for (let i = 0; i < SplittedChangedFiles.length; i++) {
SplittedChangedFiles[i] = ChangedFiles.slice(i === 0 ? i : i * 20, (i + 1) * 20 > ChangedFiles.length ? ChangedFiles.length : (i + 1) * 20)
}
ChangedFiles = null

// Make requests
for (const Changed of ChangedFiles) {
const CDNResponses:Array<string> = []
for (let Changed of SplittedChangedFiles) {
let CDNResponses:Array<string> = []
while(CDNResponses.length === 0 ||
!(CDNResponses.some(async (CDNResponse) => {
const CDNStatus:JSON = await Got.got.get(`https://purge.jsdelivr.net/status/${CDNResponse}`, { https: { minVersion: 'TLSv1.3' }, http2: true }).json()
let CDNStatus:JSON = await Got.got.get(`https://purge.jsdelivr.net/status/${CDNResponse}`, { https: { minVersion: 'TLSv1.3' }, http2: true }).json()
return CDNStatus['status'] === 'finished' || CDNStatus['status'] === 'failed'}))
) {
const CDNRequest:JSON = await Got.got.post('https://purge.jsdelivr.net/', {
let CDNRequest:JSON = await Got.got.post('https://purge.jsdelivr.net/', {
headers: { 'cache-control': 'no-cache' },
json: {
'path': [`/gh/${RepoOwner}/${RepoName}@${Message}/${Changed}`]
'path': Changed.map(element => `/gh/${RepoOwner}/${RepoName}@${Message}/${element}`)
},
https: { minVersion: 'TLSv1.3' }, http2: true }).json()
Actions.info(`Thread for ${Message}: Sent new request having ${CDNRequest['id']} ID.`)
CDNResponses.push(CDNRequest['id'])
await new Promise(resolve => setTimeout(resolve, 5000))
}
Actions.info(`Thread for ${Message}: jsDelivr server returns that ${Changed} is purged.`)
Actions.info(`Thread for ${Message}: jsDelivr server returns that the following files are purged:
${Changed.join('\n - ').replace(/^/, ' - ')}
`)
}

Actions.info(`Thread for ${Message}: All changed files are purged. Exiting...`)
Expand Down

0 comments on commit 3e8583f

Please sign in to comment.