Преглед изворни кода

resume from this.lock.workon

Mike L пре 3 година
родитељ
комит
6f8f888810
2 измењених фајлова са 6 додато и 4 уклоњено
  1. 3 2
      dist/twitter.js
  2. 3 2
      src/twitter.ts

+ 3 - 2
dist/twitter.js

@@ -316,8 +316,9 @@ class default_1 {
                     fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
                 }
             });
-            utils_1.chainPromises(utils_1.Arr.chunk(lock.feed.slice(0).reverse(), 5).map((arr, i) => () => Promise.all(arr.map((currentFeed, j) => {
-                lock.workon = (lock.feed.length - 1) - i * 5 + j;
+            const queuedFeeds = lock.feed.slice(0, lock.workon ? lock.workon + 1 : undefined).reverse();
+            utils_1.chainPromises(utils_1.Arr.chunk(queuedFeeds, 5).map((arr, i) => () => Promise.all(arr.map((currentFeed, j) => {
+                lock.workon = (queuedFeeds.length - 1) - i * 5 + j;
                 fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
                 const promiseDelay = this.workInterval * (Math.random() + j) * 500 / lock.feed.length;
                 logger.debug(`timeout for this pull job: ${promiseDelay * 2}`);

+ 3 - 2
src/twitter.ts

@@ -493,9 +493,10 @@ export default class {
       }
     });
     
-    chainPromises(Arr.chunk(lock.feed.slice(0).reverse(), 5).map((arr, i) =>
+    const queuedFeeds = lock.feed.slice(0, lock.workon ? lock.workon + 1 : undefined).reverse();
+    chainPromises(Arr.chunk(queuedFeeds, 5).map((arr, i) =>
       () => Promise.all(arr.map((currentFeed, j) => {
-        lock.workon = (lock.feed.length - 1) - i * 5 + j;
+        lock.workon = (queuedFeeds.length - 1) - i * 5 + j;
         fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
 
         const promiseDelay = this.workInterval * (Math.random() + j) * 500 / lock.feed.length;