@stemy/backend 6.1.1 → 6.1.3

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.
@@ -710,7 +710,7 @@ function copy(obj) {
710
710
  return copyRecursive(null, obj, defaultPredicate, new Map());
711
711
  }
712
712
  function assign(target, source, predicate) {
713
- return copyRecursive(target, source, predicate, new Map());
713
+ return copyRecursive(target, source, predicate || defaultPredicate, new Map());
714
714
  }
715
715
  function md5(data) {
716
716
  if (isObject(data)) {
@@ -1447,6 +1447,33 @@ let JobManager = class JobManager {
1447
1447
  apiPull;
1448
1448
  workerPush;
1449
1449
  workerPull;
1450
+ zmqStats = {
1451
+ apiPush: {
1452
+ sent: 0,
1453
+ received: 0,
1454
+ lastSentAt: 0,
1455
+ lastReceivedAt: 0
1456
+ },
1457
+ apiPull: {
1458
+ sent: 0,
1459
+ received: 0,
1460
+ lastSentAt: 0,
1461
+ lastReceivedAt: 0
1462
+ },
1463
+ workerPush: {
1464
+ sent: 0,
1465
+ received: 0,
1466
+ lastSentAt: 0,
1467
+ lastReceivedAt: 0
1468
+ },
1469
+ workerPull: {
1470
+ sent: 0,
1471
+ received: 0,
1472
+ lastSentAt: 0,
1473
+ lastReceivedAt: 0
1474
+ }
1475
+ };
1476
+ zmqDiagnosticsTimer;
1450
1477
  maxTimeout;
1451
1478
  constructor(config, logger, container, jobTypes) {
1452
1479
  this.config = config;
@@ -1461,7 +1488,14 @@ let JobManager = class JobManager {
1461
1488
  sendMessage: (message, params) => {
1462
1489
  params.uniqueId = uniqueId;
1463
1490
  this.workerPush.then(sock => {
1464
- sock.send([message, JSON.stringify(params)]);
1491
+ try {
1492
+ sock.send([message, JSON.stringify(params)]);
1493
+ this.zmqStats.workerPush.sent++;
1494
+ this.zmqStats.workerPush.lastSentAt = Date.now();
1495
+ }
1496
+ catch (e) {
1497
+ this.logger.log("job-manager", `ZMQ workerPush send failed: ${e.message}`);
1498
+ }
1465
1499
  });
1466
1500
  }
1467
1501
  };
@@ -1472,6 +1506,7 @@ let JobManager = class JobManager {
1472
1506
  }, {});
1473
1507
  this.messages = new Subject();
1474
1508
  this.maxTimeout = this.config.resolve("jobTimeout");
1509
+ this.startZmqDiagnostics();
1475
1510
  }
1476
1511
  on(message, cb) {
1477
1512
  return this.messages
@@ -1531,6 +1566,8 @@ let JobManager = class JobManager {
1531
1566
  const sock = socket("pull");
1532
1567
  sock.connect(pullHost);
1533
1568
  sock.on("message", async (name, args, uniqId) => {
1569
+ this.zmqStats.workerPull.received++;
1570
+ this.zmqStats.workerPull.lastReceivedAt = Date.now();
1534
1571
  try {
1535
1572
  const jobName = name.toString("utf8");
1536
1573
  const jobParams = JSON.parse(args.toString("utf8"));
@@ -1589,11 +1626,13 @@ let JobManager = class JobManager {
1589
1626
  resolve(sock);
1590
1627
  });
1591
1628
  });
1592
- this.apiPull = this.apiPush || new Promise(resolve => {
1629
+ this.apiPull = this.apiPull || new Promise(resolve => {
1593
1630
  const backPort = this.config.resolve("zmqBackPort");
1594
1631
  const sock = socket("pull");
1595
1632
  sock.bind(`tcp://0.0.0.0:${backPort}`, () => {
1596
1633
  sock.on("message", (name, args) => {
1634
+ this.zmqStats.apiPull.received++;
1635
+ this.zmqStats.apiPull.lastReceivedAt = Date.now();
1597
1636
  const message = name.toString("utf8");
1598
1637
  const params = JSON.parse(args?.toString("utf8") || "{}");
1599
1638
  const paramTypes = Object.keys(params).reduce((res, key) => {
@@ -1621,9 +1660,36 @@ let JobManager = class JobManager {
1621
1660
  async sendToWorkers(jobName, params) {
1622
1661
  const uniqueId = new ObjectId$1().toHexString();
1623
1662
  const sock = await this.apiPush;
1624
- sock.send([jobName, JSON.stringify(params), uniqueId]);
1663
+ try {
1664
+ sock.send([jobName, JSON.stringify(params), uniqueId]);
1665
+ this.zmqStats.apiPush.sent++;
1666
+ this.zmqStats.apiPush.lastSentAt = Date.now();
1667
+ }
1668
+ catch (e) {
1669
+ this.logger.log("job-manager", `ZMQ API PUSH send failed: ${e.message}`);
1670
+ throw e;
1671
+ }
1625
1672
  return uniqueId;
1626
1673
  }
1674
+ startZmqDiagnostics() {
1675
+ this.zmqDiagnosticsTimer = setInterval(() => {
1676
+ const now = Date.now();
1677
+ const age = (timestamp) => {
1678
+ if (!timestamp) {
1679
+ return "never";
1680
+ }
1681
+ return `${Math.round((now - timestamp) / 1000)}s ago`;
1682
+ };
1683
+ this.logger.log("job-manager", [
1684
+ "ZMQ diagnostics:",
1685
+ `apiPush(sent=${this.zmqStats.apiPush.sent}, lastSent=${age(this.zmqStats.apiPush.lastSentAt)})`,
1686
+ `apiPull(received=${this.zmqStats.apiPull.received}, lastReceived=${age(this.zmqStats.apiPull.lastReceivedAt)})`,
1687
+ `workerPush(sent=${this.zmqStats.workerPush.sent}, lastSent=${age(this.zmqStats.workerPush.lastSentAt)})`,
1688
+ `workerPull(received=${this.zmqStats.workerPull.received}, lastReceived=${age(this.zmqStats.workerPull.lastReceivedAt)})`
1689
+ ].join(" | "));
1690
+ }, 30_000);
1691
+ this.zmqDiagnosticsTimer.unref?.();
1692
+ }
1627
1693
  };
1628
1694
  JobManager = __decorate([
1629
1695
  singleton(),