Add retry mechanism in case of episodes list retrieve failure instead of just failing.

If it can't after a couple of retry (5 by default, can be changed on the command line) it will just ignore it and go to the next anime.
This commit is contained in:
Godzil 2018-06-11 21:16:39 +01:00
parent f3a0d0129d
commit 7d6f762f59
3 changed files with 23 additions and 4 deletions

View File

@ -64,9 +64,25 @@ export default function(args: string[], done: (err?: Error) => void)
{
if (errin)
{
return done(errin);
if (tasksArr[i].retry <= 0)
{
console.error(err.stack || err);
console.error('Cannot get episodes from "' + tasksArr[i].address + '", please rerun later');
}
else
{
if (config.verbose)
{
console.error(err.stack || err);
}
console.warn('Retrying to fetch episodes ' + tasksArr[i].retry + ' / ' + config.retry);
tasksArr[i].retry -= 1;
}
}
else
{
i += 1;
}
i += 1;
next();
});
})();
@ -118,7 +134,7 @@ function tasks(config: IConfigLine, batchPath: string, done: (err: Error, tasks?
return done(null, config.args.map((addressIn) =>
{
return {address: addressIn, config: configIn};
return {address: addressIn, config: configIn, retry: config.retry};
}));
}
@ -154,7 +170,7 @@ function tasks(config: IConfigLine, batchPath: string, done: (err: Error, tasks?
return;
}
map.push({address: addressIn, config: lineConfig});
map.push({address: addressIn, config: lineConfig, retry: config.retry});
});
});
done(null, map);
@ -188,5 +204,6 @@ function parse(args: string[]): IConfigLine
.option('-g, --rebuildcrp', 'Rebuild the crpersistant file.')
.option('-b, --batch <s>', 'Batch file', 'CrunchyRoll.txt')
.option('--verbose', 'Make tool verbose')
.option('--retry <i>', 'Number or time to retry fetching an episode. Default: 5', 5)
.parse(args);
}

View File

@ -20,4 +20,5 @@ interface IConfig {
rebuildcrp?: boolean;
batch?: string;
verbose?: boolean;
retry?: number;
}

View File

@ -1,4 +1,5 @@
interface IConfigTask {
address: string;
config: IConfigLine;
retry: number;
}