@stemy/backend 3.1.3 → 3.1.4

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.
@@ -2413,18 +2413,21 @@
2413
2413
  this.container = container;
2414
2414
  this.jobTypes = jobTypes || [];
2415
2415
  this.jobs = this.jobTypes.reduce(function (res, jobType) {
2416
- res[getConstructorName(jobType)] = function (jobParams) {
2416
+ var jobName = getConstructorName(jobType);
2417
+ res[jobName] = function (jobParams, uniqueId) {
2417
2418
  var job = _this.resolveJobInstance(jobType, jobParams);
2418
- return job.process(_this.messageBridge);
2419
+ var messageBridge = {
2420
+ sendMessage: function (message, params) {
2421
+ params.uniqueId = uniqueId;
2422
+ _this.workerPush.send([message, JSON.stringify(params)]);
2423
+ }
2424
+ };
2425
+ messageBridge.sendMessage("job-started", { name: jobName });
2426
+ return job.process(messageBridge);
2419
2427
  };
2420
2428
  return res;
2421
2429
  }, {});
2422
2430
  this.messages = new rxjs.Subject();
2423
- this.messageBridge = {
2424
- sendMessage: function (message, params) {
2425
- _this.workerPush.send([message, JSON.stringify(params)]);
2426
- }
2427
- };
2428
2431
  this.processing = false;
2429
2432
  this.maxTimeout = this.config.resolve("jobTimeout");
2430
2433
  }
@@ -2517,32 +2520,31 @@
2517
2520
  case 2:
2518
2521
  _a.sent();
2519
2522
  console.log("Worker consumer connected to: " + pullHost);
2520
- this.workerPull.on("message", function (name, args, uniqueId) { return __awaiter$o(_this, void 0, void 0, function () {
2521
- var jobName, jobParams, timerId, e_1, e_2;
2523
+ this.workerPull.on("message", function (name, args, uniqId) { return __awaiter$o(_this, void 0, void 0, function () {
2524
+ var jobName, jobParams, uniqueId, e_1, e_2;
2522
2525
  return __generator(this, function (_a) {
2523
2526
  switch (_a.label) {
2524
2527
  case 0:
2525
2528
  _a.trys.push([0, 5, , 6]);
2526
2529
  jobName = name.toString("utf8");
2527
2530
  jobParams = JSON.parse(args.toString("utf8"));
2528
- timerId = uniqueId === null || uniqueId === void 0 ? void 0 : uniqueId.toString("utf8");
2529
- console.time(timerId);
2530
- console.timeLog(timerId, "Started working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + " with args: \n" + jsonHighlight(jobParams) + "\n\n");
2531
- this.messageBridge.sendMessage("job-started", { name: jobName });
2531
+ uniqueId = uniqId === null || uniqId === void 0 ? void 0 : uniqId.toString("utf8");
2532
+ console.time(uniqueId);
2533
+ console.timeLog(uniqueId, "Started working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + " with args: \n" + jsonHighlight(jobParams) + "\n\n");
2532
2534
  _a.label = 1;
2533
2535
  case 1:
2534
2536
  _a.trys.push([1, 3, , 4]);
2535
- return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams), promiseTimeout(this.maxTimeout, true)])];
2537
+ return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams, uniqueId), promiseTimeout(this.maxTimeout, true)])];
2536
2538
  case 2:
2537
2539
  _a.sent();
2538
- console.timeLog(timerId, "Finished working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + "\n\n");
2540
+ console.timeLog(uniqueId, "Finished working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + "\n\n");
2539
2541
  return [3 /*break*/, 4];
2540
2542
  case 3:
2541
2543
  e_1 = _a.sent();
2542
- console.timeLog(timerId, "Background job failed: " + colorize(jobName, exports.ConsoleColor.FgRed) + "\n" + e_1 + "\n\n");
2544
+ console.timeLog(uniqueId, "Background job failed: " + colorize(jobName, exports.ConsoleColor.FgRed) + "\n" + e_1 + "\n\n");
2543
2545
  return [3 /*break*/, 4];
2544
2546
  case 4:
2545
- console.timeEnd(timerId);
2547
+ console.timeEnd(uniqueId);
2546
2548
  return [3 /*break*/, 6];
2547
2549
  case 5:
2548
2550
  e_2 = _a.sent();
@@ -2611,16 +2613,17 @@
2611
2613
  };
2612
2614
  JobManager.prototype.sendToWorkers = function (jobName, params) {
2613
2615
  return __awaiter$o(this, void 0, void 0, function () {
2614
- var publisher;
2616
+ var publisher, uniqueId;
2615
2617
  return __generator(this, function (_a) {
2616
2618
  switch (_a.label) {
2617
2619
  case 0: return [4 /*yield*/, this.apiPush];
2618
2620
  case 1:
2619
2621
  publisher = _a.sent();
2620
- return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), new bson.ObjectId().toHexString()])];
2622
+ uniqueId = new bson.ObjectId().toHexString();
2623
+ return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), uniqueId])];
2621
2624
  case 2:
2622
2625
  _a.sent();
2623
- return [2 /*return*/];
2626
+ return [2 /*return*/, uniqueId];
2624
2627
  }
2625
2628
  });
2626
2629
  });