Browse Source

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.
Godzil 6 years ago
parent
commit
7d6f762f59
3 changed files with 23 additions and 4 deletions
  1. 21 4
      src/batch.ts
  2. 1 0
      src/interface/IConfig.d.ts
  3. 1 0
      src/interface/IConfigTask.d.ts

+ 21 - 4
src/batch.ts

@@ -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);
 }

+ 1 - 0
src/interface/IConfig.d.ts

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

+ 1 - 0
src/interface/IConfigTask.d.ts

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