Mike L преди 3 години
родител
ревизия
19b24efd66
променени са 2 файла, в които са добавени 12 реда и са изтрити 10 реда
  1. 6 5
      dist/twitter.js
  2. 6 5
      src/twitter.ts

+ 6 - 5
dist/twitter.js

@@ -361,13 +361,14 @@ class default_1 {
             });
             const queuedFeeds = lock.feed.slice(0, (lock.workon + 1) || undefined).reverse();
             utils_1.chainPromises(utils_1.Arr.chunk(queuedFeeds, 5).map((arr, i) => () => Promise.all(arr.map((currentFeed, j) => {
-                if (Date.now() - new Date(lock.threads[currentFeed].updatedAt).getTime() < 3600000)
-                    return;
-                const workon = (queuedFeeds.length - 1) - (i * 5 + j);
-                fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
                 const promiseDelay = this.workInterval * (Math.random() + j) * 250 / lock.feed.length;
+                const wait = (ms) => isWaitingForLogin ? utils_1.neverResolves() : util_1.promisify(setTimeout)(ms);
                 const startTime = new Date().getTime();
                 const getTimerTime = () => new Date().getTime() - startTime;
+                if (Date.now() - new Date(lock.threads[currentFeed].updatedAt).getTime() < 3600000)
+                    return wait(promiseDelay);
+                const workon = (queuedFeeds.length - 1) - (i * 5 + j);
+                fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
                 const promise = util_1.promisify(setTimeout)(promiseDelay * 3).then(() => {
                     logger.info(`about to pull from feed #${workon}: ${currentFeed}`);
                     if (j === arr.length - 1)
@@ -380,7 +381,7 @@ class default_1 {
                     }
                     fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
                 });
-                return Promise.race([promise, isWaitingForLogin ? utils_1.neverResolves() : util_1.promisify(setTimeout)(promiseDelay * 4)]);
+                return Promise.race([promise, wait(promiseDelay * 4)]);
             })))).then(this.work);
         };
         this.client = new instagram_private_api_1.IgApiClient();

+ 6 - 5
src/twitter.ts

@@ -582,14 +582,15 @@ export default class {
     const queuedFeeds = lock.feed.slice(0, (lock.workon + 1) || undefined).reverse();
     chainPromises(Arr.chunk(queuedFeeds, 5).map((arr, i) =>
       () => Promise.all(arr.map((currentFeed, j) => {
-        if (Date.now() - new Date(lock.threads[currentFeed].updatedAt).getTime() < 3600000) return;
-
-        const workon = (queuedFeeds.length - 1) - (i * 5 + j);
-        fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
         const promiseDelay = this.workInterval * (Math.random() + j) * 250 / lock.feed.length;
+        const wait = (ms: number) => isWaitingForLogin ? neverResolves() : promisify(setTimeout)(ms);
         const startTime = new Date().getTime();
         const getTimerTime = () => new Date().getTime() - startTime;
 
+        if (Date.now() - new Date(lock.threads[currentFeed].updatedAt).getTime() < 3600000) return wait(promiseDelay);
+
+        const workon = (queuedFeeds.length - 1) - (i * 5 + j);
+        fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
         const promise = promisify(setTimeout)(promiseDelay * 3).then(() => {
           logger.info(`about to pull from feed #${workon}: ${currentFeed}`);
           if (j === arr.length - 1) logger.info(`timeout for this batch job: ${Math.trunc(promiseDelay)} ms`);
@@ -602,7 +603,7 @@ export default class {
           fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
         });
 
-        return Promise.race([promise, isWaitingForLogin ? neverResolves() : promisify(setTimeout)(promiseDelay * 4)]);
+        return Promise.race([promise, wait(promiseDelay * 4)]);
       }))
     )).then(this.work);
   };