roboto-js 1.4.22 → 1.4.24

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.
@@ -429,20 +429,39 @@ var Roboto = exports["default"] = /*#__PURE__*/function () {
429
429
  return runTask;
430
430
  }()
431
431
  }, {
432
- key: "pollTaskProgress",
432
+ key: "stopJob",
433
433
  value: function () {
434
- var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
434
+ var _stopJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params, callbacks) {
435
435
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
436
436
  while (1) switch (_context17.prev = _context17.next) {
437
437
  case 0:
438
- return _context17.abrupt("return", this.api.pollTaskProgress(params));
438
+ return _context17.abrupt("return", this.api.stopJob(params, callbacks));
439
439
  case 1:
440
440
  case "end":
441
441
  return _context17.stop();
442
442
  }
443
443
  }, _callee17, this);
444
444
  }));
445
- function pollTaskProgress(_x15) {
445
+ function stopJob(_x15, _x16) {
446
+ return _stopJob.apply(this, arguments);
447
+ }
448
+ return stopJob;
449
+ }()
450
+ }, {
451
+ key: "pollTaskProgress",
452
+ value: function () {
453
+ var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
454
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
455
+ while (1) switch (_context18.prev = _context18.next) {
456
+ case 0:
457
+ return _context18.abrupt("return", this.api.pollTaskProgress(params));
458
+ case 1:
459
+ case "end":
460
+ return _context18.stop();
461
+ }
462
+ }, _callee18, this);
463
+ }));
464
+ function pollTaskProgress(_x17) {
446
465
  return _pollTaskProgress.apply(this, arguments);
447
466
  }
448
467
  return pollTaskProgress;
@@ -452,18 +471,18 @@ var Roboto = exports["default"] = /*#__PURE__*/function () {
452
471
  }, {
453
472
  key: "get",
454
473
  value: function () {
455
- var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(endpoint, params) {
456
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
457
- while (1) switch (_context18.prev = _context18.next) {
474
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(endpoint, params) {
475
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
476
+ while (1) switch (_context19.prev = _context19.next) {
458
477
  case 0:
459
- return _context18.abrupt("return", this.api.get(endpoint, params));
478
+ return _context19.abrupt("return", this.api.get(endpoint, params));
460
479
  case 1:
461
480
  case "end":
462
- return _context18.stop();
481
+ return _context19.stop();
463
482
  }
464
- }, _callee18, this);
483
+ }, _callee19, this);
465
484
  }));
466
- function get(_x16, _x17) {
485
+ function get(_x18, _x19) {
467
486
  return _get.apply(this, arguments);
468
487
  }
469
488
  return get;
@@ -471,18 +490,18 @@ var Roboto = exports["default"] = /*#__PURE__*/function () {
471
490
  }, {
472
491
  key: "post",
473
492
  value: function () {
474
- var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(endpoint, data) {
475
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
476
- while (1) switch (_context19.prev = _context19.next) {
493
+ var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(endpoint, data) {
494
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
495
+ while (1) switch (_context20.prev = _context20.next) {
477
496
  case 0:
478
- return _context19.abrupt("return", this.api.post(endpoint, data));
497
+ return _context20.abrupt("return", this.api.post(endpoint, data));
479
498
  case 1:
480
499
  case "end":
481
- return _context19.stop();
500
+ return _context20.stop();
482
501
  }
483
- }, _callee19, this);
502
+ }, _callee20, this);
484
503
  }));
485
- function post(_x18, _x19) {
504
+ function post(_x20, _x21) {
486
505
  return _post.apply(this, arguments);
487
506
  }
488
507
  return post;
@@ -831,7 +831,12 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
831
831
  }()
832
832
  /**
833
833
  * Makes a POST request to a specific endpoint to run a task and handle progress updates.
834
- *
834
+ *
835
+ * @param params.id (optional) IF the client is MONITORING the job with WS ClientMonitor,
836
+ * the client should generate a jobId and connect to the ClientMonitor
837
+ * BEFORE starting the job, to make sure no messages are missed -
838
+ * otherwise we'd have to delay the task start.
839
+ *
835
840
  * @param {Object} params - The parameters to be sent in the POST request.
836
841
  * @param {Object} callbacks - An object containing callback functions for progress and error handling.
837
842
  *
@@ -851,7 +856,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
851
856
  callbacks,
852
857
  onProgress,
853
858
  onError,
854
- onFinish,
859
+ onStopped,
860
+ onDone,
855
861
  response,
856
862
  ok,
857
863
  jobId,
@@ -864,7 +870,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
864
870
  case 0:
865
871
  params = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {};
866
872
  callbacks = _args18.length > 1 && _args18[1] !== undefined ? _args18[1] : {};
867
- onProgress = callbacks.onProgress, onError = callbacks.onError, onFinish = callbacks.onFinish;
873
+ onProgress = callbacks.onProgress, onError = callbacks.onError, onStopped = callbacks.onStopped, onDone = callbacks.onDone;
868
874
  _context18.prev = 3;
869
875
  _context18.next = 6;
870
876
  return this.post('/task_service/runChain', params);
@@ -885,17 +891,21 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
885
891
  throw new Error('Invalid response structure');
886
892
  case 12:
887
893
  // If the task is still in progress, start polling for updates
888
- if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED') {
894
+ if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED' || status === 'STOPPING') {
889
895
  this.pollTaskProgress(jobId, callbacks);
890
896
  }
891
897
  if (status === 'ERROR' && onError) {
892
898
  // Provide the current progress to the callback function
893
899
  onError(response);
894
900
  }
895
- if (status === 'DONE' && onFinish) {
901
+ if (status === 'STOPPED' && onError) {
902
+ // Provide the current progress to the callback function
903
+ onStopped(response);
904
+ }
905
+ if (status === 'DONE' && onDone) {
896
906
  // Provide the current progress to the callback function
897
907
  console.log('Finish (request) ', response);
898
- onFinish(response);
908
+ onDone(response);
899
909
  }
900
910
  return _context18.abrupt("return", {
901
911
  ok: ok,
@@ -904,8 +914,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
904
914
  message: message,
905
915
  output: output
906
916
  });
907
- case 18:
908
- _context18.prev = 18;
917
+ case 19:
918
+ _context18.prev = 19;
909
919
  _context18.t0 = _context18["catch"](3);
910
920
  if (typeof onError === 'function') {
911
921
  onError(_context18.t0);
@@ -918,16 +928,56 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
918
928
  status: 'ERROR',
919
929
  error: _context18.t0.message
920
930
  });
921
- case 22:
931
+ case 23:
922
932
  case "end":
923
933
  return _context18.stop();
924
934
  }
925
- }, _callee18, this, [[3, 18]]);
935
+ }, _callee18, this, [[3, 19]]);
926
936
  }));
927
937
  function runTask() {
928
938
  return _runTask.apply(this, arguments);
929
939
  }
930
940
  return runTask;
941
+ }())
942
+ }, {
943
+ key: "stopJob",
944
+ value: function () {
945
+ var _stopJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
946
+ var params,
947
+ callbacks,
948
+ response,
949
+ _args19 = arguments;
950
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
951
+ while (1) switch (_context19.prev = _context19.next) {
952
+ case 0:
953
+ params = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {};
954
+ callbacks = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : {};
955
+ _context19.prev = 2;
956
+ _context19.next = 5;
957
+ return this.post('/task_service/stopJob', params);
958
+ case 5:
959
+ response = _context19.sent;
960
+ if (response) {
961
+ _context19.next = 8;
962
+ break;
963
+ }
964
+ throw new Error('Invalid server response');
965
+ case 8:
966
+ return _context19.abrupt("return", true);
967
+ case 11:
968
+ _context19.prev = 11;
969
+ _context19.t0 = _context19["catch"](2);
970
+ throw 'Error in stopJob';
971
+ case 14:
972
+ case "end":
973
+ return _context19.stop();
974
+ }
975
+ }, _callee19, this, [[2, 11]]);
976
+ }));
977
+ function stopJob() {
978
+ return _stopJob.apply(this, arguments);
979
+ }
980
+ return stopJob;
931
981
  }()
932
982
  /**
933
983
  * Polls the progress of a long-running task.
@@ -939,35 +989,34 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
939
989
  * and reports back via the provided callback function . The polling stops when
940
990
  * the task is completed or an error occurs.
941
991
  */
942
- )
943
992
  }, {
944
993
  key: "pollTaskProgress",
945
994
  value: (function () {
946
- var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(jobId, callbacks) {
995
+ var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(jobId, callbacks) {
947
996
  var _this2 = this;
948
- var onProgress, onError, onFinish, checkProgress;
949
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
950
- while (1) switch (_context20.prev = _context20.next) {
997
+ var onProgress, onError, onDone, checkProgress;
998
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
999
+ while (1) switch (_context21.prev = _context21.next) {
951
1000
  case 0:
952
- onProgress = callbacks.onProgress, onError = callbacks.onError, onFinish = callbacks.onFinish;
953
- _context20.prev = 1;
1001
+ onProgress = callbacks.onProgress, onError = callbacks.onError, onDone = callbacks.onDone;
1002
+ _context21.prev = 1;
954
1003
  checkProgress = /*#__PURE__*/function () {
955
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1004
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
956
1005
  var response;
957
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
958
- while (1) switch (_context19.prev = _context19.next) {
1006
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1007
+ while (1) switch (_context20.prev = _context20.next) {
959
1008
  case 0:
960
- _context19.next = 2;
1009
+ _context20.next = 2;
961
1010
  return _this2.get("/task_service/pollChainProgress", {
962
1011
  jobId: jobId
963
1012
  });
964
1013
  case 2:
965
- response = _context19.sent;
1014
+ response = _context20.sent;
966
1015
  // If the task is still in progress, start polling for updates
967
- if (response.status === 'DONE' && onFinish) {
1016
+ if (response.status === 'DONE' && onDone) {
968
1017
  // Provide the current progress to the callback function
969
1018
  console.log('Finish (progress) ', response);
970
- onFinish(response);
1019
+ onDone(response);
971
1020
  }
972
1021
  if (response.status === 'ERROR' && onError) {
973
1022
  // Provide the current progress to the callback function
@@ -985,26 +1034,26 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
985
1034
  }
986
1035
  case 7:
987
1036
  case "end":
988
- return _context19.stop();
1037
+ return _context20.stop();
989
1038
  }
990
- }, _callee19);
1039
+ }, _callee20);
991
1040
  }));
992
1041
  return function checkProgress() {
993
1042
  return _ref2.apply(this, arguments);
994
1043
  };
995
1044
  }();
996
1045
  checkProgress();
997
- _context20.next = 9;
1046
+ _context21.next = 9;
998
1047
  break;
999
1048
  case 6:
1000
- _context20.prev = 6;
1001
- _context20.t0 = _context20["catch"](1);
1002
- return _context20.abrupt("return", this._handleError(_context20.t0));
1049
+ _context21.prev = 6;
1050
+ _context21.t0 = _context21["catch"](1);
1051
+ return _context21.abrupt("return", this._handleError(_context21.t0));
1003
1052
  case 9:
1004
1053
  case "end":
1005
- return _context20.stop();
1054
+ return _context21.stop();
1006
1055
  }
1007
- }, _callee20, this, [[1, 6]]);
1056
+ }, _callee21, this, [[1, 6]]);
1008
1057
  }));
1009
1058
  function pollTaskProgress(_x14, _x15) {
1010
1059
  return _pollTaskProgress.apply(this, arguments);
@@ -1026,44 +1075,44 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1026
1075
  }, {
1027
1076
  key: "get",
1028
1077
  value: (function () {
1029
- var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(endpoint) {
1078
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(endpoint) {
1030
1079
  var params,
1031
1080
  headers,
1032
1081
  response,
1033
- _args21 = arguments;
1034
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1035
- while (1) switch (_context21.prev = _context21.next) {
1082
+ _args22 = arguments;
1083
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1084
+ while (1) switch (_context22.prev = _context22.next) {
1036
1085
  case 0:
1037
- params = _args21.length > 1 && _args21[1] !== undefined ? _args21[1] : {};
1086
+ params = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
1038
1087
  debugger;
1039
- _context21.prev = 2;
1088
+ _context22.prev = 2;
1040
1089
  // Add the authToken to the headers
1041
1090
  headers = {
1042
1091
  authtoken: this.authtoken
1043
1092
  }; // Make the GET request using Axios
1044
- _context21.next = 6;
1093
+ _context22.next = 6;
1045
1094
  return this.axios.get(endpoint, {
1046
1095
  params: params,
1047
1096
  headers: headers
1048
1097
  });
1049
1098
  case 6:
1050
- response = _context21.sent;
1099
+ response = _context22.sent;
1051
1100
  if (!(response.data.ok === false)) {
1052
- _context21.next = 9;
1101
+ _context22.next = 9;
1053
1102
  break;
1054
1103
  }
1055
- return _context21.abrupt("return", this._handleError(response));
1104
+ return _context22.abrupt("return", this._handleError(response));
1056
1105
  case 9:
1057
- return _context21.abrupt("return", response.data);
1106
+ return _context22.abrupt("return", response.data);
1058
1107
  case 12:
1059
- _context21.prev = 12;
1060
- _context21.t0 = _context21["catch"](2);
1061
- return _context21.abrupt("return", this._handleError(_context21.t0));
1108
+ _context22.prev = 12;
1109
+ _context22.t0 = _context22["catch"](2);
1110
+ return _context22.abrupt("return", this._handleError(_context22.t0));
1062
1111
  case 15:
1063
1112
  case "end":
1064
- return _context21.stop();
1113
+ return _context22.stop();
1065
1114
  }
1066
- }, _callee21, this, [[2, 12]]);
1115
+ }, _callee22, this, [[2, 12]]);
1067
1116
  }));
1068
1117
  function get(_x16) {
1069
1118
  return _get.apply(this, arguments);
@@ -1086,42 +1135,42 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1086
1135
  }, {
1087
1136
  key: "post",
1088
1137
  value: (function () {
1089
- var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(endpoint) {
1138
+ var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(endpoint) {
1090
1139
  var data,
1091
1140
  headers,
1092
1141
  response,
1093
- _args22 = arguments;
1094
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1095
- while (1) switch (_context22.prev = _context22.next) {
1142
+ _args23 = arguments;
1143
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1144
+ while (1) switch (_context23.prev = _context23.next) {
1096
1145
  case 0:
1097
- data = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
1098
- _context22.prev = 1;
1146
+ data = _args23.length > 1 && _args23[1] !== undefined ? _args23[1] : {};
1147
+ _context23.prev = 1;
1099
1148
  // Add the authToken to the headers
1100
1149
  headers = {
1101
1150
  authtoken: this.authtoken
1102
1151
  }; // Make the POST request using Axios
1103
- _context22.next = 5;
1152
+ _context23.next = 5;
1104
1153
  return this.axios.post(endpoint, data, {
1105
1154
  headers: headers
1106
1155
  });
1107
1156
  case 5:
1108
- response = _context22.sent;
1157
+ response = _context23.sent;
1109
1158
  if (!(response.data.ok === false)) {
1110
- _context22.next = 8;
1159
+ _context23.next = 8;
1111
1160
  break;
1112
1161
  }
1113
- return _context22.abrupt("return", this._handleError(response));
1162
+ return _context23.abrupt("return", this._handleError(response));
1114
1163
  case 8:
1115
- return _context22.abrupt("return", response.data);
1164
+ return _context23.abrupt("return", response.data);
1116
1165
  case 11:
1117
- _context22.prev = 11;
1118
- _context22.t0 = _context22["catch"](1);
1119
- return _context22.abrupt("return", this._handleError(_context22.t0));
1166
+ _context23.prev = 11;
1167
+ _context23.t0 = _context23["catch"](1);
1168
+ return _context23.abrupt("return", this._handleError(_context23.t0));
1120
1169
  case 14:
1121
1170
  case "end":
1122
- return _context22.stop();
1171
+ return _context23.stop();
1123
1172
  }
1124
- }, _callee22, this, [[1, 11]]);
1173
+ }, _callee23, this, [[1, 11]]);
1125
1174
  }));
1126
1175
  function post(_x17) {
1127
1176
  return _post.apply(this, arguments);
package/dist/esm/index.js CHANGED
@@ -131,6 +131,9 @@ export default class Roboto {
131
131
  async runTask(params, callbacks) {
132
132
  return this.api.runTask(params, callbacks);
133
133
  }
134
+ async stopJob(params, callbacks) {
135
+ return this.api.stopJob(params, callbacks);
136
+ }
134
137
  async pollTaskProgress(params) {
135
138
  return this.api.pollTaskProgress(params);
136
139
  }
@@ -403,7 +403,12 @@ export default class RbtApi {
403
403
 
404
404
  /**
405
405
  * Makes a POST request to a specific endpoint to run a task and handle progress updates.
406
- *
406
+ *
407
+ * @param params.id (optional) IF the client is MONITORING the job with WS ClientMonitor,
408
+ * the client should generate a jobId and connect to the ClientMonitor
409
+ * BEFORE starting the job, to make sure no messages are missed -
410
+ * otherwise we'd have to delay the task start.
411
+ *
407
412
  * @param {Object} params - The parameters to be sent in the POST request.
408
413
  * @param {Object} callbacks - An object containing callback functions for progress and error handling.
409
414
  *
@@ -418,7 +423,8 @@ export default class RbtApi {
418
423
  const {
419
424
  onProgress,
420
425
  onError,
421
- onFinish
426
+ onStopped,
427
+ onDone
422
428
  } = callbacks;
423
429
  try {
424
430
  const response = await this.post('/task_service/runChain', params);
@@ -440,17 +446,21 @@ export default class RbtApi {
440
446
  }
441
447
 
442
448
  // If the task is still in progress, start polling for updates
443
- if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED') {
449
+ if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED' || status === 'STOPPING') {
444
450
  this.pollTaskProgress(jobId, callbacks);
445
451
  }
446
452
  if (status === 'ERROR' && onError) {
447
453
  // Provide the current progress to the callback function
448
454
  onError(response);
449
455
  }
450
- if (status === 'DONE' && onFinish) {
456
+ if (status === 'STOPPED' && onError) {
457
+ // Provide the current progress to the callback function
458
+ onStopped(response);
459
+ }
460
+ if (status === 'DONE' && onDone) {
451
461
  // Provide the current progress to the callback function
452
462
  console.log('Finish (request) ', response);
453
- onFinish(response);
463
+ onDone(response);
454
464
  }
455
465
  return {
456
466
  ok,
@@ -473,6 +483,18 @@ export default class RbtApi {
473
483
  };
474
484
  }
475
485
  }
486
+ async stopJob(params = {}, callbacks = {}) {
487
+ try {
488
+ const response = await this.post('/task_service/stopJob', params);
489
+ // Check if response and response.data are defined
490
+ if (!response) {
491
+ throw new Error('Invalid server response');
492
+ }
493
+ return true;
494
+ } catch (e) {
495
+ throw 'Error in stopJob';
496
+ }
497
+ }
476
498
 
477
499
  /**
478
500
  * Polls the progress of a long-running task.
@@ -488,7 +510,7 @@ export default class RbtApi {
488
510
  const {
489
511
  onProgress,
490
512
  onError,
491
- onFinish
513
+ onDone
492
514
  } = callbacks;
493
515
  try {
494
516
  const checkProgress = async () => {
@@ -497,10 +519,10 @@ export default class RbtApi {
497
519
  });
498
520
 
499
521
  // If the task is still in progress, start polling for updates
500
- if (response.status === 'DONE' && onFinish) {
522
+ if (response.status === 'DONE' && onDone) {
501
523
  // Provide the current progress to the callback function
502
524
  console.log('Finish (progress) ', response);
503
- onFinish(response);
525
+ onDone(response);
504
526
  }
505
527
  if (response.status === 'ERROR' && onError) {
506
528
  // Provide the current progress to the callback function
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.22",
3
+ "version": "1.4.24",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/index.js CHANGED
@@ -154,6 +154,9 @@ export default class Roboto{
154
154
  async runTask(params, callbacks){
155
155
  return this.api.runTask(params, callbacks);
156
156
  }
157
+ async stopJob(params, callbacks){
158
+ return this.api.stopJob(params, callbacks);
159
+ }
157
160
 
158
161
  async pollTaskProgress(params){
159
162
  return this.api.pollTaskProgress(params);
package/src/rbt_api.js CHANGED
@@ -461,7 +461,12 @@ export default class RbtApi {
461
461
 
462
462
  /**
463
463
  * Makes a POST request to a specific endpoint to run a task and handle progress updates.
464
- *
464
+ *
465
+ * @param params.id (optional) IF the client is MONITORING the job with WS ClientMonitor,
466
+ * the client should generate a jobId and connect to the ClientMonitor
467
+ * BEFORE starting the job, to make sure no messages are missed -
468
+ * otherwise we'd have to delay the task start.
469
+ *
465
470
  * @param {Object} params - The parameters to be sent in the POST request.
466
471
  * @param {Object} callbacks - An object containing callback functions for progress and error handling.
467
472
  *
@@ -473,7 +478,7 @@ export default class RbtApi {
473
478
  * }
474
479
  */
475
480
  async runTask(params = {}, callbacks = {}) {
476
- const { onProgress, onError, onFinish } = callbacks;
481
+ const { onProgress, onError, onStopped, onDone } = callbacks;
477
482
 
478
483
  try {
479
484
  const response = await this.post('/task_service/runChain', params);
@@ -489,17 +494,21 @@ export default class RbtApi {
489
494
  }
490
495
 
491
496
  // If the task is still in progress, start polling for updates
492
- if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED') {
497
+ if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED' || status === 'STOPPING') {
493
498
  this.pollTaskProgress(jobId, callbacks);
494
499
  }
495
500
  if (status === 'ERROR' && onError){
496
501
  // Provide the current progress to the callback function
497
502
  onError(response);
498
503
  }
499
- if (status === 'DONE' && onFinish){
504
+ if (status === 'STOPPED' && onError){
500
505
  // Provide the current progress to the callback function
501
- console.log('Finish (request) ',response);
502
- onFinish(response);
506
+ onStopped(response);
507
+ }
508
+ if (status === 'DONE' && onDone){
509
+ // Provide the current progress to the callback function
510
+ console.log('Finish (request) ',response);
511
+ onDone(response);
503
512
  }
504
513
 
505
514
  return { ok, jobId, status, message, output };
@@ -516,6 +525,23 @@ export default class RbtApi {
516
525
  }
517
526
  }
518
527
 
528
+ async stopJob(params = {}, callbacks = {}) {
529
+
530
+ try {
531
+ const response = await this.post('/task_service/stopJob', params);
532
+ // Check if response and response.data are defined
533
+ if (!response) {
534
+ throw new Error('Invalid server response');
535
+ }
536
+ return true;
537
+
538
+ } catch (e) {
539
+
540
+ throw 'Error in stopJob';
541
+
542
+ }
543
+ }
544
+
519
545
 
520
546
  /**
521
547
  * Polls the progress of a long-running task.
@@ -528,16 +554,16 @@ export default class RbtApi {
528
554
  * the task is completed or an error occurs.
529
555
  */
530
556
  async pollTaskProgress(jobId, callbacks) {
531
- const { onProgress, onError, onFinish } = callbacks;
557
+ const { onProgress, onError, onDone } = callbacks;
532
558
  try {
533
559
  const checkProgress = async () => {
534
560
  const response = await this.get(`/task_service/pollChainProgress`, { jobId: jobId });
535
561
 
536
562
  // If the task is still in progress, start polling for updates
537
- if (response.status === 'DONE' && onFinish){
563
+ if (response.status === 'DONE' && onDone){
538
564
  // Provide the current progress to the callback function
539
565
  console.log('Finish (progress) ',response);
540
- onFinish(response);
566
+ onDone(response);
541
567
  }
542
568
  if (response.status === 'ERROR' && onError){
543
569
  // Provide the current progress to the callback function