Skip to content

Commit

Permalink
improve nocapd output
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Sep 10, 2024
1 parent ae1d654 commit 2200e8d
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions apps/nocapd/src/classes/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,40 +243,60 @@ export class NWWorker {
return percentage.toFixed(2) + "%";
}



async progressMessage(url, result={}, error=false){


this.log.debug(`progressMessage()`)
const failure = chalk.red;
const success = chalk.bold.green;
const mute = chalk.gray

let duration = 0
const incD = ( _d ) => duration += _d > 0? _d: 0

let progress = ''
progress += `[${chalk.bgBlack(this.calculateProgress())}] `
progress += `${mute(this.processed++)}/${mute(this.total)} `
progress += `${url}: `
if(this.checks.includes('open'))

if(this.checks.includes('open')) {
progress += `${result?.open?.data === true? success("online"): failure("offline")} `
if(this.checks.includes('read'))
incD(result?.open?.duration)
}
if(this.checks.includes('read')) {
progress += `${result?.read?.data === true? success("readable"): failure("unreadable")} `
if(this.checks.includes('write'))
incD(result?.read?.duration)
}
if(this.checks.includes('write')) {
progress += `${result?.write?.data === true? success("writable"): failure("unwritable")} `
if(this.checks.includes('ssl'))
incD(result?.write?.duration)
}
if(this.checks.includes('ssl')){
progress += `${Object.keys(result?.ssl?.data || {}).length? success("ssl"): failure("ssl")} `
if(this.checks.includes('dns'))
incD(result?.ssl?.duration)
}
if(this.checks.includes('dns')){
progress += `${Object.keys(result?.dns?.data || {}).length? success("dns"): failure("dns")} `
if(this.checks.includes('geo'))
incD(result?.dns?.duration)
}
if(this.checks.includes('geo')){
progress += `${Object.keys(result?.geo?.data || {}).length? success("geo"): failure("geo")} `
if(this.checks.includes('info'))
incD(result?.geo?.duration)
}
if(this.checks.includes('info')){
progress += `${Object.keys(result?.info?.data || {}).length? success("info"): failure("info")} `

incD(result?.info?.duration)
}
if(!error){
progress += `${(result?.open?.duration+result?.read?.duration+result?.write?.duration)/1000} seconds `
progress += `${duration/1000} seconds `
}

if(error) {
const retries = await this.retry.getRetries(url)
progress += `${error? chalk.gray.italic('error'): ''} `
progress += `[${retries !== null? retries: 0} retries]`
}

this.log.info(progress)
}

Expand Down

0 comments on commit 2200e8d

Please sign in to comment.