Adding 5s sleep between retry and fixing retry logic.

This commit is contained in:
Vahagn Khachatryan
2019-02-03 08:55:57 +00:00
parent 086cd4c72b
commit 5365385bd5

View File

@@ -1,4 +1,9 @@
var concurrency = 5
var retry_delay = 15/* seconds */
function sleep(delay) {
return new Promise((resolve) => setTimeout(resolve, delay*1000));
}
function getCurrentTab() {
console.debug("Querying active tab.");
@@ -65,7 +70,8 @@ class Book{
.catch((error)=>{
if (!retry){
console.warn(`Failed ${url} - ${error.message}`)
return this.downloadResource(url, true)
return sleep(retry_delay)
.then(()=>{return this.downloadResource(url, true)})
} else {
console.error(`Giving up on ${url} - ${error.message}`)
throw `Failed second try on ${url} - ${error.message}`
@@ -76,7 +82,8 @@ class Book{
return res
} else if (!retry){
console.warn(`Failed ${url} - ${res.status} - ${res.statusText}`)
return this.downloadResource(url, true)
return sleep(retry_delay)
.then(()=>{return this.downloadResource(url, true)})
} else {
console.error(`Giving up on ${url} - ${res.status} - ${res.statusText}`)
throw `Failed second try on ${url} - ${res.status} - ${res.statusText}`
@@ -174,6 +181,11 @@ class Book{
downloadContent(){
return Promise.map(Object.keys(this.book_files), (url) => {
return this.downloadContentFile(url)
},{concurrency: concurrency})
}
downloadContentFile(url){
return this.downloadAndReport(url, this.book_files[url].filename)
.then((res) => {
if (res.ok){
@@ -187,7 +199,6 @@ class Book{
.catch((error)=>{
throw `Failed to download book content: "${error}"`
})
},{concurrency: concurrency})
}
insertBookFile(url, filename){