roboto-js 1.4.22 → 1.4.23
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.
- package/dist/cjs/rbt_api.cjs +113 -64
- package/dist/esm/rbt_api.js +30 -8
- package/package.json +1 -1
- package/src/rbt_api.js +35 -9
package/dist/cjs/rbt_api.cjs
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
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 === '
|
|
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
|
-
|
|
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
|
|
908
|
-
_context18.prev =
|
|
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
|
|
931
|
+
case 23:
|
|
922
932
|
case "end":
|
|
923
933
|
return _context18.stop();
|
|
924
934
|
}
|
|
925
|
-
}, _callee18, this, [[3,
|
|
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
|
|
995
|
+
var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(jobId, callbacks) {
|
|
947
996
|
var _this2 = this;
|
|
948
|
-
var onProgress, onError,
|
|
949
|
-
return _regeneratorRuntime().wrap(function
|
|
950
|
-
while (1) switch (
|
|
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,
|
|
953
|
-
|
|
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
|
|
1004
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
956
1005
|
var response;
|
|
957
|
-
return _regeneratorRuntime().wrap(function
|
|
958
|
-
while (1) switch (
|
|
1006
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1007
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
959
1008
|
case 0:
|
|
960
|
-
|
|
1009
|
+
_context20.next = 2;
|
|
961
1010
|
return _this2.get("/task_service/pollChainProgress", {
|
|
962
1011
|
jobId: jobId
|
|
963
1012
|
});
|
|
964
1013
|
case 2:
|
|
965
|
-
response =
|
|
1014
|
+
response = _context20.sent;
|
|
966
1015
|
// If the task is still in progress, start polling for updates
|
|
967
|
-
if (response.status === 'DONE' &&
|
|
1016
|
+
if (response.status === 'DONE' && onDone) {
|
|
968
1017
|
// Provide the current progress to the callback function
|
|
969
1018
|
console.log('Finish (progress) ', response);
|
|
970
|
-
|
|
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
|
|
1037
|
+
return _context20.stop();
|
|
989
1038
|
}
|
|
990
|
-
},
|
|
1039
|
+
}, _callee20);
|
|
991
1040
|
}));
|
|
992
1041
|
return function checkProgress() {
|
|
993
1042
|
return _ref2.apply(this, arguments);
|
|
994
1043
|
};
|
|
995
1044
|
}();
|
|
996
1045
|
checkProgress();
|
|
997
|
-
|
|
1046
|
+
_context21.next = 9;
|
|
998
1047
|
break;
|
|
999
1048
|
case 6:
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
return
|
|
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
|
|
1054
|
+
return _context21.stop();
|
|
1006
1055
|
}
|
|
1007
|
-
},
|
|
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
|
|
1078
|
+
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(endpoint) {
|
|
1030
1079
|
var params,
|
|
1031
1080
|
headers,
|
|
1032
1081
|
response,
|
|
1033
|
-
|
|
1034
|
-
return _regeneratorRuntime().wrap(function
|
|
1035
|
-
while (1) switch (
|
|
1082
|
+
_args22 = arguments;
|
|
1083
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1084
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1036
1085
|
case 0:
|
|
1037
|
-
params =
|
|
1086
|
+
params = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
|
|
1038
1087
|
debugger;
|
|
1039
|
-
|
|
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
|
-
|
|
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 =
|
|
1099
|
+
response = _context22.sent;
|
|
1051
1100
|
if (!(response.data.ok === false)) {
|
|
1052
|
-
|
|
1101
|
+
_context22.next = 9;
|
|
1053
1102
|
break;
|
|
1054
1103
|
}
|
|
1055
|
-
return
|
|
1104
|
+
return _context22.abrupt("return", this._handleError(response));
|
|
1056
1105
|
case 9:
|
|
1057
|
-
return
|
|
1106
|
+
return _context22.abrupt("return", response.data);
|
|
1058
1107
|
case 12:
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
return
|
|
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
|
|
1113
|
+
return _context22.stop();
|
|
1065
1114
|
}
|
|
1066
|
-
},
|
|
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
|
|
1138
|
+
var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(endpoint) {
|
|
1090
1139
|
var data,
|
|
1091
1140
|
headers,
|
|
1092
1141
|
response,
|
|
1093
|
-
|
|
1094
|
-
return _regeneratorRuntime().wrap(function
|
|
1095
|
-
while (1) switch (
|
|
1142
|
+
_args23 = arguments;
|
|
1143
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1144
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1096
1145
|
case 0:
|
|
1097
|
-
data =
|
|
1098
|
-
|
|
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
|
-
|
|
1152
|
+
_context23.next = 5;
|
|
1104
1153
|
return this.axios.post(endpoint, data, {
|
|
1105
1154
|
headers: headers
|
|
1106
1155
|
});
|
|
1107
1156
|
case 5:
|
|
1108
|
-
response =
|
|
1157
|
+
response = _context23.sent;
|
|
1109
1158
|
if (!(response.data.ok === false)) {
|
|
1110
|
-
|
|
1159
|
+
_context23.next = 8;
|
|
1111
1160
|
break;
|
|
1112
1161
|
}
|
|
1113
|
-
return
|
|
1162
|
+
return _context23.abrupt("return", this._handleError(response));
|
|
1114
1163
|
case 8:
|
|
1115
|
-
return
|
|
1164
|
+
return _context23.abrupt("return", response.data);
|
|
1116
1165
|
case 11:
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
return
|
|
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
|
|
1171
|
+
return _context23.stop();
|
|
1123
1172
|
}
|
|
1124
|
-
},
|
|
1173
|
+
}, _callee23, this, [[1, 11]]);
|
|
1125
1174
|
}));
|
|
1126
1175
|
function post(_x17) {
|
|
1127
1176
|
return _post.apply(this, arguments);
|
package/dist/esm/rbt_api.js
CHANGED
|
@@ -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
|
-
|
|
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 === '
|
|
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
|
-
|
|
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
|
-
|
|
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' &&
|
|
522
|
+
if (response.status === 'DONE' && onDone) {
|
|
501
523
|
// Provide the current progress to the callback function
|
|
502
524
|
console.log('Finish (progress) ', response);
|
|
503
|
-
|
|
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
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,
|
|
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 === '
|
|
504
|
+
if (status === 'STOPPED' && onError){
|
|
500
505
|
// Provide the current progress to the callback function
|
|
501
|
-
|
|
502
|
-
|
|
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,
|
|
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' &&
|
|
563
|
+
if (response.status === 'DONE' && onDone){
|
|
538
564
|
// Provide the current progress to the callback function
|
|
539
565
|
console.log('Finish (progress) ',response);
|
|
540
|
-
|
|
566
|
+
onDone(response);
|
|
541
567
|
}
|
|
542
568
|
if (response.status === 'ERROR' && onError){
|
|
543
569
|
// Provide the current progress to the callback function
|