twitter.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const fs = require("fs");
  4. const log4js = require("log4js");
  5. const path = require("path");
  6. const logger = log4js.getLogger('twitter');
  7. logger.level = 'info';
  8. function work(lock, lockfile) {
  9. if (lock.feed.length === 0) {
  10. setTimeout(() => {
  11. work(lock, lockfile);
  12. }, 60000);
  13. return;
  14. }
  15. if (lock.workon >= lock.feed.length)
  16. lock.workon = 0;
  17. if (!lock.threads[lock.feed[lock.workon]] ||
  18. !lock.threads[lock.feed[lock.workon]].subscribers ||
  19. lock.threads[lock.feed[lock.workon]].subscribers.length === 0) {
  20. logger.error(`nobody subscribes thread ${lock.feed[lock.workon]}, removing from feed`);
  21. lock.feed.splice(lock.workon, 1);
  22. fs.writeFileSync(path.resolve(lockfile), JSON.stringify(lock));
  23. work(lock, lockfile);
  24. return;
  25. }
  26. // TODO: Work on lock.feed[lock.workon]
  27. lock.workon++;
  28. fs.writeFileSync(path.resolve(lockfile), JSON.stringify(lock));
  29. setTimeout(() => {
  30. work(lock, lockfile);
  31. }, 60000);
  32. }
  33. exports.default = work;