feat: retry if failed
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
parent
89b2517ffc
commit
953981ef34
64
bin/index.js
64
bin/index.js
|
@ -55,40 +55,55 @@ async function run () {
|
||||||
const num = pad(i, 4)
|
const num = pad(i, 4)
|
||||||
const dir = join(argv.dir, num)
|
const dir = join(argv.dir, num)
|
||||||
|
|
||||||
|
progress(`📦 Fetching ${i} out of ${latest}`)
|
||||||
|
|
||||||
if (await fs.pathExists(dir)) {
|
if (await fs.pathExists(dir)) {
|
||||||
const data = await fs.readJSON(join(dir, 'info.json'))
|
const data = await fs.readJSON(join(dir, 'info.json'))
|
||||||
added.push({ id: i, title: data.title, num })
|
added.push({ id: i, title: data.title, num })
|
||||||
await fs.outputFile(join(dir, 'index.html'), comicPage(data))
|
await fs.outputFile(join(dir, 'index.html'), comicPage(data))
|
||||||
continue
|
continue
|
||||||
} else if (i === 404) {
|
} else if (i === 404) {
|
||||||
progress(`📦 404 not found 😵`)
|
|
||||||
continue
|
continue
|
||||||
} else {
|
|
||||||
progress(`📦 Fetching ${i} out of ${latest}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let comic = null
|
let comic = null
|
||||||
|
|
||||||
try {
|
const info = {
|
||||||
comic = await getComic(i)
|
|
||||||
} catch (err) {
|
|
||||||
progress(`😢 Could not fetch ${i}, will try again later\n`)
|
|
||||||
errored.push(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
await write(comic, dir)
|
|
||||||
added.push({
|
|
||||||
id: i,
|
id: i,
|
||||||
title: comic.data.title,
|
title: comic.data.title,
|
||||||
|
dir: dir,
|
||||||
num: num
|
num: num
|
||||||
})
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
comic = await getComic(i)
|
||||||
|
await write(comic, dir)
|
||||||
|
added.push(info)
|
||||||
|
} catch (err) {
|
||||||
|
progress(`😢 Could not fetch ${i}, will try again later\n`)
|
||||||
|
errored.push(info)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`🐉 ${err.stack}`)
|
console.log(`🐉 ${err.stack}`)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: redownload errored
|
for (const info of errored) {
|
||||||
|
const { id, dir, num } = info
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
try {
|
||||||
|
const comic = await getComic(id)
|
||||||
|
await write(comic, dir)
|
||||||
|
added.push(info)
|
||||||
|
break
|
||||||
|
} catch (err) {
|
||||||
|
if (i === 2) {
|
||||||
|
console.log(`😢 ${num} could not be fetched: ${err.toString()}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (errored.length === 0) {
|
if (errored.length === 0) {
|
||||||
progress(`📦 All comics fetched\n`)
|
progress(`📦 All comics fetched\n`)
|
||||||
|
@ -100,26 +115,5 @@ async function run () {
|
||||||
await fs.copyFile(join(__dirname, '../node_modules/tachyons/css/tachyons.min.css'), join(argv.dir, 'tachyons.css'))
|
await fs.copyFile(join(__dirname, '../node_modules/tachyons/css/tachyons.min.css'), join(argv.dir, 'tachyons.css'))
|
||||||
await fs.outputFile(join(argv.dir, 'index.html'), homePage(added))
|
await fs.outputFile(join(argv.dir, 'index.html'), homePage(added))
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
|
||||||
const clone = async ({ baseDir, empty, onlyMissing }) => {
|
|
||||||
/*
|
|
||||||
|
|
||||||
for (const num of errored) {
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
try {
|
|
||||||
const comic = await getComic(i)
|
|
||||||
await write(comic, dir)
|
|
||||||
break
|
|
||||||
} catch (err) {
|
|
||||||
if (i === 2) {
|
|
||||||
console.log(`😢 ${num} could not be fetched: ${err.toString()}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user