utiller 1.0.84 → 1.0.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,6 +59,8 @@ var InfinitePool = /*#__PURE__*/function () {
59
59
 
60
60
  /** 如果要讓每個pool不會因為task掉進catch 而被中斷, 就必須加入taskFailHandler*/
61
61
 
62
+ /** 如果設定sleep interval, 可以加這個參數要不要先執行第一次 再開始 interval 機制*/
63
+
62
64
  /** 用於 runByParam */
63
65
 
64
66
  /** runByTimes 的次數 */
@@ -90,8 +92,8 @@ var InfinitePool = /*#__PURE__*/function () {
90
92
  (0, _defineProperty2["default"])(this, "enableOfTaskTimeout", _configerer.configerer.POOLLER_ENABLE_TIMEOUT);
91
93
  (0, _defineProperty2["default"])(this, "timeOfTaskTimeout", _configerer.configerer.POOLLER_TASK_TIMEOUT_DEFAULT);
92
94
  (0, _defineProperty2["default"])(this, "handlerOfAssignTaskFail", undefined);
93
- (0, _defineProperty2["default"])(this, "maxWorker", void 0);
94
- (0, _defineProperty2["default"])(this, "ignoreFirstRun", false);
95
+ (0, _defineProperty2["default"])(this, "maximumOfWorker", void 0);
96
+ (0, _defineProperty2["default"])(this, "disableFirstRun", false);
95
97
  (0, _defineProperty2["default"])(this, "queueOfWaitingParam", []);
96
98
  (0, _defineProperty2["default"])(this, "countsOfRunByTimes", -1);
97
99
  (0, _defineProperty2["default"])(this, "queueOfAssignTask", {});
@@ -348,7 +350,7 @@ var InfinitePool = /*#__PURE__*/function () {
348
350
  throw new _exceptioner["default"](4006, "type of task is ===> ".concat((0, _typeof2["default"])(task)));
349
351
 
350
352
  case 12:
351
- _this.enableTaskSleepInterval(!!interval, interval);
353
+ _this.enableTaskSleepInterval(_lodash["default"].isNumber(interval), interval);
352
354
 
353
355
  _this.setState(_configerer.configerer.POOLLER_STATE.RUN_INFINITE);
354
356
 
@@ -636,7 +638,7 @@ var InfinitePool = /*#__PURE__*/function () {
636
638
  return "TASK HASH: ".concat(hash);
637
639
  });
638
640
  (0, _defineProperty2["default"])(this, "showState", function () {
639
- _index2.utiller.appendInfo(_this.getPoollerLogFormat("workerCount: ".concat(_this.maxWorker)));
641
+ _index2.utiller.appendInfo(_this.getPoollerLogFormat("workerCount: ".concat(_this.maximumOfWorker)));
640
642
 
641
643
  _index2.utiller.appendInfo(_this.getPoollerLogFormat("taskQueue(\u9084\u5728\u6392\u968A\u7684Task): ".concat(_this.getCountOfAssignTaskInQueue())));
642
644
 
@@ -718,7 +720,7 @@ var InfinitePool = /*#__PURE__*/function () {
718
720
  _this.printLogMessage("4574152 \u4E0D\u61C9\u8A72\u8D70\u5230\u9019\u88CF,\u4F46\u662F minor issue", true);
719
721
 
720
722
  case 14:
721
- if (_this.queueOfExecutingTask.length > _this.maxWorker) _this.printLogMessage("4512214 \u4E00\u5B9A\u662F\u6539\u58DE\u4E86!!!!!!!!!!, ".concat(_this.getLogMessageOfExecutingTaskQueueCount, " "), true);
723
+ if (_this.queueOfExecutingTask.length > _this.maximumOfWorker) _this.printLogMessage("4512214 \u4E00\u5B9A\u662F\u6539\u58DE\u4E86!!!!!!!!!!, ".concat(_this.getLogMessageOfExecutingTaskQueueCount, " "), true);
722
724
 
723
725
  case 15:
724
726
  case "end":
@@ -825,7 +827,7 @@ var InfinitePool = /*#__PURE__*/function () {
825
827
 
826
828
  return _this;
827
829
  });
828
- this.maxWorker = maxWorkers;
830
+ this.maximumOfWorker = maxWorkers;
829
831
  this.setPoolId(_lodash["default"].toString(name));
830
832
 
831
833
  var _iterator4 = _createForOfIteratorHelper(_configerer.configerer.POOLLER_PRIORITY),
@@ -886,7 +888,7 @@ var InfinitePool = /*#__PURE__*/function () {
886
888
  }, {
887
889
  key: "setWorker",
888
890
  value: function setWorker(counts) {
889
- this.maxWorker = counts;
891
+ this.maximumOfWorker = counts;
890
892
  }
891
893
  }, {
892
894
  key: "cleanTaskInterval",
@@ -1042,10 +1044,10 @@ var InfinitePool = /*#__PURE__*/function () {
1042
1044
  /** 如果設定interval, 第一個run不要執行的話,就設定true, default是false */
1043
1045
 
1044
1046
  }, {
1045
- key: "setIgnoreFirstRun",
1046
- value: function setIgnoreFirstRun() {
1047
- var ignore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1048
- this.ignoreFirstRun = ignore;
1047
+ key: "setDisableFirstRun",
1048
+ value: function setDisableFirstRun() {
1049
+ var disable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1050
+ this.disableFirstRun = disable;
1049
1051
  }
1050
1052
  /** 加上一個 被動式啟動, 不然一直while() run, 可能有效能上的問題,現階端只支援RUN_BY_TASK */
1051
1053
 
@@ -1070,7 +1072,7 @@ var InfinitePool = /*#__PURE__*/function () {
1070
1072
  }, {
1071
1073
  key: "isExecutingQueueFull",
1072
1074
  value: function isExecutingQueueFull() {
1073
- return _lodash["default"].size(this.queueOfExecutingTask) >= this.maxWorker;
1075
+ return _lodash["default"].size(this.queueOfExecutingTask) >= this.maximumOfWorker;
1074
1076
  }
1075
1077
  }, {
1076
1078
  key: "isTaskQueueEmpty",
@@ -1083,54 +1085,59 @@ var InfinitePool = /*#__PURE__*/function () {
1083
1085
  key: "syncTaskDispatcher",
1084
1086
  value: function () {
1085
1087
  var _syncTaskDispatcher = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() {
1086
- var initialTaskShouldNotRun, restInInterval, taskInfo, promise;
1088
+ var initialTaskShouldNotRun, isExecutingTaskAlmostFull, comparison, restInInterval, taskInfo, promise;
1087
1089
  return _regenerator["default"].wrap(function _callee10$(_context10) {
1088
1090
  while (1) {
1089
1091
  switch (_context10.prev = _context10.next) {
1090
1092
  case 0:
1091
- initialTaskShouldNotRun = this.ignoreFirstRun && !this.isFirstTaskCompleted();
1093
+ initialTaskShouldNotRun = this.disableFirstRun && !this.isFirstTaskCompleted();
1094
+ isExecutingTaskAlmostFull = this.queueOfExecutingTask.length >= this.maximumOfWorker - 1;
1095
+ /** 因為走能到syncTaskDispatcher表示其中一個工作完成了, 這個瞬間不可能 === maximumOfWorker,
1096
+ * 所以必須減1, 除非這個syncTaskDispatcher是單獨一個線程 */
1097
+
1098
+ comparison = this.isFirstTaskCompleted() && isExecutingTaskAlmostFull && this.enableOfTaskSleepByInterval;
1092
1099
 
1093
- if (!(initialTaskShouldNotRun || this.isFirstTaskCompleted() && this.isExecutingQueueFull() && this.enableOfTaskSleepByInterval)) {
1094
- _context10.next = 6;
1100
+ if (!(initialTaskShouldNotRun || comparison)) {
1101
+ _context10.next = 8;
1095
1102
  break;
1096
1103
  }
1097
1104
 
1098
- _context10.next = 4;
1105
+ _context10.next = 6;
1099
1106
  return _index2.utiller.syncDelayRandom(this.taskSleepInterval.min, this.taskSleepInterval.max);
1100
1107
 
1101
- case 4:
1108
+ case 6:
1102
1109
  restInInterval = _context10.sent;
1103
1110
  this.printLogMessage("4484121, \u8D70\u5230\u4E00\u5761\u7761\u89BA\u5340 enableOfTaskSleepByInterval:".concat(this.enableOfTaskSleepByInterval, " || ").concat(restInInterval, " ms"));
1104
1111
 
1105
- case 6:
1112
+ case 8:
1106
1113
  if (!this.rulesOfAppendToExecutingTask()) {
1107
- _context10.next = 18;
1114
+ _context10.next = 20;
1108
1115
  break;
1109
1116
  }
1110
1117
 
1111
1118
  taskInfo = this.getTaskInfoDependOnPriority();
1112
1119
 
1113
1120
  if (!taskInfo) {
1114
- _context10.next = 14;
1121
+ _context10.next = 16;
1115
1122
  break;
1116
1123
  }
1117
1124
 
1118
1125
  promise = this.taskWrapper(taskInfo.task, taskInfo.hash, this.queueOfWaitingParam.shift());
1119
1126
  this.removeTaskMapByHash(taskInfo.hash);
1120
1127
  this.appendTaskToExecuteQueue(taskInfo.hash, promise);
1121
- _context10.next = 16;
1128
+ _context10.next = 18;
1122
1129
  break;
1123
1130
 
1124
- case 14:
1131
+ case 16:
1125
1132
  /** 沒有taskInfo, 也許有未知的isssue,保險起見break */
1126
1133
  this.printLogMessage("848451 \u4E5F\u8A31\u6709\u672A\u77E5\u7684isssue,\u4FDD\u96AA\u8D77\u898Bbreak,\u662F\u4E0D\u662F\u5728\u9019\u88E1\u7121\u9650\u8FF4\u5708\u8DD1\u8DD1\u8DD1", true);
1127
- return _context10.abrupt("break", 18);
1134
+ return _context10.abrupt("break", 20);
1128
1135
 
1129
- case 16:
1130
- _context10.next = 6;
1136
+ case 18:
1137
+ _context10.next = 8;
1131
1138
  break;
1132
1139
 
1133
- case 18:
1140
+ case 20:
1134
1141
  case "end":
1135
1142
  return _context10.stop();
1136
1143
  }
@@ -1317,7 +1324,7 @@ var InfinitePool = /*#__PURE__*/function () {
1317
1324
 
1318
1325
  pool = new InfinitePool(2);
1319
1326
  pool.runInfiniteInBackground(myAsyncTask, 5000);
1320
- pool.setIgnoreFirstRun(true);
1327
+ pool.setDisableFirstRun(true);
1321
1328
  pool.setTaskFailHandler(function (error) {
1322
1329
  console.error(error.message);
1323
1330
  });
@@ -1647,7 +1654,7 @@ var InfinitePool = /*#__PURE__*/function () {
1647
1654
  case 0:
1648
1655
  _persistTone = function _persistTone3() {
1649
1656
  _persistTone = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee27() {
1650
- var sign;
1657
+ var sign, time;
1651
1658
  return _regenerator["default"].wrap(function _callee27$(_context27) {
1652
1659
  while (1) {
1653
1660
  switch (_context27.prev = _context27.next) {
@@ -1655,34 +1662,28 @@ var InfinitePool = /*#__PURE__*/function () {
1655
1662
  _context27.prev = 0;
1656
1663
  sign = _index2.utiller.getRandomHash(20);
1657
1664
  _context27.next = 4;
1658
- return _index2.utiller.syncDelay(1000);
1665
+ return _index2.utiller.syncDelayRandom(1, 10);
1659
1666
 
1660
1667
  case 4:
1661
- _context27.t0 = _index2.utiller;
1662
- _context27.t1 = "\u6C92\u6709TONE\u53EF\u4EE5\u4E0B\u8F09\u4E86....\u96A8\u6A5F\u7761\u500B";
1663
- _context27.next = 8;
1664
- return _index2.utiller.syncDelayRandom(1500, 3500);
1668
+ time = _context27.sent;
1665
1669
 
1666
- case 8:
1667
- _context27.t2 = _context27.sent;
1668
- _context27.t3 = _context27.t1.concat.call(_context27.t1, _context27.t2);
1670
+ _index2.utiller.appendInfo("".concat(time, " ms, yoyoyo ").concat(sign)); // Util.appendInfo(`沒有TONE可以下載了....隨機睡個${await Util.syncDelayRandom(1500, 3500)}`)
1669
1671
 
1670
- _context27.t0.appendInfo.call(_context27.t0, _context27.t3);
1671
1672
 
1672
1673
  return _context27.abrupt("return", "\u4EFB\u52D9ID:".concat(sign));
1673
1674
 
1674
- case 14:
1675
- _context27.prev = 14;
1676
- _context27.t4 = _context27["catch"](0);
1675
+ case 9:
1676
+ _context27.prev = 9;
1677
+ _context27.t0 = _context27["catch"](0);
1677
1678
 
1678
- _index2.utiller.appendError(_context27.t4.message);
1679
+ _index2.utiller.appendError(_context27.t0.message);
1679
1680
 
1680
- case 17:
1681
+ case 12:
1681
1682
  case "end":
1682
1683
  return _context27.stop();
1683
1684
  }
1684
1685
  }
1685
- }, _callee27, null, [[0, 14]]);
1686
+ }, _callee27, null, [[0, 9]]);
1686
1687
  }));
1687
1688
  return _persistTone.apply(this, arguments);
1688
1689
  };
@@ -1692,10 +1693,10 @@ var InfinitePool = /*#__PURE__*/function () {
1692
1693
  };
1693
1694
 
1694
1695
  poollers = [];
1695
- pool = new InfinitePool(2);
1696
+ pool = new InfinitePool(3);
1696
1697
  pool.setPoolId("tone fetch");
1697
- pool.setIgnoreFirstRun(false);
1698
- pool.runInfiniteInBackground(persistTone, 3000);
1698
+ pool.setDisableFirstRun(true);
1699
+ pool.runInfiniteInBackground(persistTone, 5000);
1699
1700
  pool.setTaskFailHandler(function (error) {
1700
1701
  return _index2.utiller.appendError("5165 error ".concat(error.message));
1701
1702
  });
@@ -1703,11 +1704,11 @@ var InfinitePool = /*#__PURE__*/function () {
1703
1704
  isRequiredTerminate = false;
1704
1705
  setTimeout(function () {
1705
1706
  isRequiredTerminate = true;
1706
- }, 10000);
1707
+ }, 20000);
1707
1708
 
1708
1709
  case 11:
1709
1710
  if (!true) {
1710
- _context28.next = 44;
1711
+ _context28.next = 43;
1711
1712
  break;
1712
1713
  }
1713
1714
 
@@ -1720,28 +1721,25 @@ var InfinitePool = /*#__PURE__*/function () {
1720
1721
 
1721
1722
  case 15:
1722
1723
  random = _context28.sent;
1723
-
1724
- _index2.utiller.appendInfo("\u4E3B\u7DDA\u7A0B\u9084\u5728\u52AA\u4E2D\u5DE5\u4F5C\u4E2D, \u4F11\u606F\u4E00\u6BC0\u5152 ".concat(random, " mms"));
1725
-
1726
- _context28.next = 19;
1724
+ _context28.next = 18;
1727
1725
  return _index2.utiller.syncDelay(random);
1728
1726
 
1729
- case 19:
1727
+ case 18:
1730
1728
  if (!isRequiredTerminate) {
1731
- _context28.next = 42;
1729
+ _context28.next = 41;
1732
1730
  break;
1733
1731
  }
1734
1732
 
1735
1733
  _index2.utiller.appendInfo("\u4E3B\u7DDA\u7A0B\u6536\u5230\u95DC\u9589\u6307\u4EE4...");
1736
1734
 
1737
1735
  _iterator6 = _createForOfIteratorHelper(poollers);
1738
- _context28.prev = 22;
1736
+ _context28.prev = 21;
1739
1737
 
1740
1738
  _iterator6.s();
1741
1739
 
1742
- case 24:
1740
+ case 23:
1743
1741
  if ((_step6 = _iterator6.n()).done) {
1744
- _context28.next = 33;
1742
+ _context28.next = 32;
1745
1743
  break;
1746
1744
  }
1747
1745
 
@@ -1749,48 +1747,48 @@ var InfinitePool = /*#__PURE__*/function () {
1749
1747
 
1750
1748
  _index2.utiller.appendInfo("POOLER ".concat(pooller.getPoolId(), " \u6B63\u5728\u95DC\u9589\u4E2D"));
1751
1749
 
1752
- _context28.next = 29;
1750
+ _context28.next = 28;
1753
1751
  return pooller.stopInBackground();
1754
1752
 
1755
- case 29:
1753
+ case 28:
1756
1754
  pooller.showState();
1757
1755
 
1758
1756
  _index2.utiller.appendInfo("POOLER ".concat(pooller.getPoolId(), " \u95DC\u9589\u6210\u529F!"));
1759
1757
 
1760
- case 31:
1761
- _context28.next = 24;
1758
+ case 30:
1759
+ _context28.next = 23;
1762
1760
  break;
1763
1761
 
1764
- case 33:
1765
- _context28.next = 38;
1762
+ case 32:
1763
+ _context28.next = 37;
1766
1764
  break;
1767
1765
 
1768
- case 35:
1769
- _context28.prev = 35;
1770
- _context28.t0 = _context28["catch"](22);
1766
+ case 34:
1767
+ _context28.prev = 34;
1768
+ _context28.t0 = _context28["catch"](21);
1771
1769
 
1772
1770
  _iterator6.e(_context28.t0);
1773
1771
 
1774
- case 38:
1775
- _context28.prev = 38;
1772
+ case 37:
1773
+ _context28.prev = 37;
1776
1774
 
1777
1775
  _iterator6.f();
1778
1776
 
1779
- return _context28.finish(38);
1777
+ return _context28.finish(37);
1780
1778
 
1781
- case 41:
1782
- return _context28.abrupt("break", 44);
1779
+ case 40:
1780
+ return _context28.abrupt("break", 43);
1783
1781
 
1784
- case 42:
1782
+ case 41:
1785
1783
  _context28.next = 11;
1786
1784
  break;
1787
1785
 
1788
- case 44:
1786
+ case 43:
1789
1787
  case "end":
1790
1788
  return _context28.stop();
1791
1789
  }
1792
1790
  }
1793
- }, _callee28, null, [[22, 35, 38, 41]]);
1791
+ }, _callee28, null, [[21, 34, 37, 40]]);
1794
1792
  }));
1795
1793
 
1796
1794
  function exampleOfInfiniteUnStopLoopingIssue() {
@@ -1128,21 +1128,21 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1128
1128
 
1129
1129
  }, {
1130
1130
  key: "copySingleFileConservative",
1131
- value: function copySingleFileConservative(pathOfDestination, latestFile) {
1131
+ value: function copySingleFileConservative(pathOfDestinationFolder, latestFile) {
1132
1132
  if (this.isEmptyFile(latestFile.absolute)) {
1133
1133
  this.appendInfo("".concat(latestFile.absolute, " is empty file, ignore copy behavior"));
1134
1134
  return;
1135
1135
  }
1136
1136
 
1137
- if (!_fs["default"].existsSync(pathOfDestination)) {
1138
- this.appendInfo("".concat(pathOfDestination, " is not exist, easy to override"));
1139
- } else if (_fs["default"].existsSync(pathOfDestination) && this.getFileLastModifiedTime(pathOfDestination) < latestFile.lastModifiedTime + 3600) {
1140
- this.appendInfo("".concat(pathOfDestination, " is the latest, ignore this run"));
1137
+ if (!_fs["default"].existsSync(pathOfDestinationFolder)) {
1138
+ this.appendInfo("".concat(pathOfDestinationFolder, " is not exist, easy to override"));
1139
+ } else if (_fs["default"].existsSync(pathOfDestinationFolder) && this.getFileLastModifiedTime(pathOfDestinationFolder) < latestFile.lastModifiedTime + 3600) {
1140
+ this.appendInfo("".concat(pathOfDestinationFolder, " is the latest, ignore this run"));
1141
1141
  return;
1142
1142
  }
1143
1143
 
1144
- this.persistByPath(this.getFolderPathOfSpecificPath(pathOfDestination));
1145
- this.copySingleFile(latestFile.absolute, pathOfDestination, undefined, true);
1144
+ this.persistByPath(this.getFolderPathOfSpecificPath(pathOfDestinationFolder));
1145
+ this.copySingleFile(latestFile.absolute, pathOfDestinationFolder, undefined, true);
1146
1146
  }
1147
1147
  }, {
1148
1148
  key: "syncDeleteFile",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.84",
3
+ "version": "1.0.85",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "configerer": "^1.0.11",
14
- "utiller": "^1.0.83",
14
+ "utiller": "^1.0.84",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.9",
17
17
  "lodash": "^4.17.20",