roboto-js 1.4.21 → 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 +128 -72
- package/dist/esm/rbt_api.js +34 -8
- package/package.json +1 -1
- package/src/rbt_api.js +40 -9
package/dist/cjs/rbt_api.cjs
CHANGED
|
@@ -483,22 +483,29 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
483
483
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
484
484
|
while (1) switch (_context11.prev = _context11.next) {
|
|
485
485
|
case 0:
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
486
|
+
if (this.appServiceHost) {
|
|
487
|
+
_context11.next = 3;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
console.warn('appServiceHost not initialized');
|
|
491
|
+
return _context11.abrupt("return", false);
|
|
489
492
|
case 3:
|
|
493
|
+
_context11.prev = 3;
|
|
494
|
+
_context11.next = 6;
|
|
495
|
+
return this.axios.post('/user_service/refreshAuthToken', [authtoken]);
|
|
496
|
+
case 6:
|
|
490
497
|
response = _context11.sent;
|
|
491
498
|
debugger;
|
|
492
499
|
return _context11.abrupt("return", response.data);
|
|
493
|
-
case 8:
|
|
494
|
-
_context11.prev = 8;
|
|
495
|
-
_context11.t0 = _context11["catch"](0);
|
|
496
|
-
this._handleError(_context11.t0);
|
|
497
500
|
case 11:
|
|
501
|
+
_context11.prev = 11;
|
|
502
|
+
_context11.t0 = _context11["catch"](3);
|
|
503
|
+
this._handleError(_context11.t0);
|
|
504
|
+
case 14:
|
|
498
505
|
case "end":
|
|
499
506
|
return _context11.stop();
|
|
500
507
|
}
|
|
501
|
-
}, _callee11, this, [[
|
|
508
|
+
}, _callee11, this, [[3, 11]]);
|
|
502
509
|
}));
|
|
503
510
|
function refreshAuthToken(_x7) {
|
|
504
511
|
return _refreshAuthToken.apply(this, arguments);
|
|
@@ -824,7 +831,12 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
824
831
|
}()
|
|
825
832
|
/**
|
|
826
833
|
* Makes a POST request to a specific endpoint to run a task and handle progress updates.
|
|
827
|
-
*
|
|
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
|
+
*
|
|
828
840
|
* @param {Object} params - The parameters to be sent in the POST request.
|
|
829
841
|
* @param {Object} callbacks - An object containing callback functions for progress and error handling.
|
|
830
842
|
*
|
|
@@ -844,7 +856,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
844
856
|
callbacks,
|
|
845
857
|
onProgress,
|
|
846
858
|
onError,
|
|
847
|
-
|
|
859
|
+
onStopped,
|
|
860
|
+
onDone,
|
|
848
861
|
response,
|
|
849
862
|
ok,
|
|
850
863
|
jobId,
|
|
@@ -857,7 +870,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
857
870
|
case 0:
|
|
858
871
|
params = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {};
|
|
859
872
|
callbacks = _args18.length > 1 && _args18[1] !== undefined ? _args18[1] : {};
|
|
860
|
-
onProgress = callbacks.onProgress, onError = callbacks.onError,
|
|
873
|
+
onProgress = callbacks.onProgress, onError = callbacks.onError, onStopped = callbacks.onStopped, onDone = callbacks.onDone;
|
|
861
874
|
_context18.prev = 3;
|
|
862
875
|
_context18.next = 6;
|
|
863
876
|
return this.post('/task_service/runChain', params);
|
|
@@ -878,17 +891,21 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
878
891
|
throw new Error('Invalid response structure');
|
|
879
892
|
case 12:
|
|
880
893
|
// If the task is still in progress, start polling for updates
|
|
881
|
-
if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED') {
|
|
894
|
+
if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED' || status === 'STOPPING') {
|
|
882
895
|
this.pollTaskProgress(jobId, callbacks);
|
|
883
896
|
}
|
|
884
897
|
if (status === 'ERROR' && onError) {
|
|
885
898
|
// Provide the current progress to the callback function
|
|
886
899
|
onError(response);
|
|
887
900
|
}
|
|
888
|
-
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) {
|
|
889
906
|
// Provide the current progress to the callback function
|
|
890
907
|
console.log('Finish (request) ', response);
|
|
891
|
-
|
|
908
|
+
onDone(response);
|
|
892
909
|
}
|
|
893
910
|
return _context18.abrupt("return", {
|
|
894
911
|
ok: ok,
|
|
@@ -897,8 +914,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
897
914
|
message: message,
|
|
898
915
|
output: output
|
|
899
916
|
});
|
|
900
|
-
case
|
|
901
|
-
_context18.prev =
|
|
917
|
+
case 19:
|
|
918
|
+
_context18.prev = 19;
|
|
902
919
|
_context18.t0 = _context18["catch"](3);
|
|
903
920
|
if (typeof onError === 'function') {
|
|
904
921
|
onError(_context18.t0);
|
|
@@ -911,16 +928,56 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
911
928
|
status: 'ERROR',
|
|
912
929
|
error: _context18.t0.message
|
|
913
930
|
});
|
|
914
|
-
case
|
|
931
|
+
case 23:
|
|
915
932
|
case "end":
|
|
916
933
|
return _context18.stop();
|
|
917
934
|
}
|
|
918
|
-
}, _callee18, this, [[3,
|
|
935
|
+
}, _callee18, this, [[3, 19]]);
|
|
919
936
|
}));
|
|
920
937
|
function runTask() {
|
|
921
938
|
return _runTask.apply(this, arguments);
|
|
922
939
|
}
|
|
923
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;
|
|
924
981
|
}()
|
|
925
982
|
/**
|
|
926
983
|
* Polls the progress of a long-running task.
|
|
@@ -932,35 +989,34 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
932
989
|
* and reports back via the provided callback function . The polling stops when
|
|
933
990
|
* the task is completed or an error occurs.
|
|
934
991
|
*/
|
|
935
|
-
)
|
|
936
992
|
}, {
|
|
937
993
|
key: "pollTaskProgress",
|
|
938
994
|
value: (function () {
|
|
939
|
-
var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
995
|
+
var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(jobId, callbacks) {
|
|
940
996
|
var _this2 = this;
|
|
941
|
-
var onProgress, onError,
|
|
942
|
-
return _regeneratorRuntime().wrap(function
|
|
943
|
-
while (1) switch (
|
|
997
|
+
var onProgress, onError, onDone, checkProgress;
|
|
998
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
999
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
944
1000
|
case 0:
|
|
945
|
-
onProgress = callbacks.onProgress, onError = callbacks.onError,
|
|
946
|
-
|
|
1001
|
+
onProgress = callbacks.onProgress, onError = callbacks.onError, onDone = callbacks.onDone;
|
|
1002
|
+
_context21.prev = 1;
|
|
947
1003
|
checkProgress = /*#__PURE__*/function () {
|
|
948
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1004
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
949
1005
|
var response;
|
|
950
|
-
return _regeneratorRuntime().wrap(function
|
|
951
|
-
while (1) switch (
|
|
1006
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1007
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
952
1008
|
case 0:
|
|
953
|
-
|
|
1009
|
+
_context20.next = 2;
|
|
954
1010
|
return _this2.get("/task_service/pollChainProgress", {
|
|
955
1011
|
jobId: jobId
|
|
956
1012
|
});
|
|
957
1013
|
case 2:
|
|
958
|
-
response =
|
|
1014
|
+
response = _context20.sent;
|
|
959
1015
|
// If the task is still in progress, start polling for updates
|
|
960
|
-
if (response.status === 'DONE' &&
|
|
1016
|
+
if (response.status === 'DONE' && onDone) {
|
|
961
1017
|
// Provide the current progress to the callback function
|
|
962
1018
|
console.log('Finish (progress) ', response);
|
|
963
|
-
|
|
1019
|
+
onDone(response);
|
|
964
1020
|
}
|
|
965
1021
|
if (response.status === 'ERROR' && onError) {
|
|
966
1022
|
// Provide the current progress to the callback function
|
|
@@ -978,26 +1034,26 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
978
1034
|
}
|
|
979
1035
|
case 7:
|
|
980
1036
|
case "end":
|
|
981
|
-
return
|
|
1037
|
+
return _context20.stop();
|
|
982
1038
|
}
|
|
983
|
-
},
|
|
1039
|
+
}, _callee20);
|
|
984
1040
|
}));
|
|
985
1041
|
return function checkProgress() {
|
|
986
1042
|
return _ref2.apply(this, arguments);
|
|
987
1043
|
};
|
|
988
1044
|
}();
|
|
989
1045
|
checkProgress();
|
|
990
|
-
|
|
1046
|
+
_context21.next = 9;
|
|
991
1047
|
break;
|
|
992
1048
|
case 6:
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
return
|
|
1049
|
+
_context21.prev = 6;
|
|
1050
|
+
_context21.t0 = _context21["catch"](1);
|
|
1051
|
+
return _context21.abrupt("return", this._handleError(_context21.t0));
|
|
996
1052
|
case 9:
|
|
997
1053
|
case "end":
|
|
998
|
-
return
|
|
1054
|
+
return _context21.stop();
|
|
999
1055
|
}
|
|
1000
|
-
},
|
|
1056
|
+
}, _callee21, this, [[1, 6]]);
|
|
1001
1057
|
}));
|
|
1002
1058
|
function pollTaskProgress(_x14, _x15) {
|
|
1003
1059
|
return _pollTaskProgress.apply(this, arguments);
|
|
@@ -1019,44 +1075,44 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1019
1075
|
}, {
|
|
1020
1076
|
key: "get",
|
|
1021
1077
|
value: (function () {
|
|
1022
|
-
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1078
|
+
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(endpoint) {
|
|
1023
1079
|
var params,
|
|
1024
1080
|
headers,
|
|
1025
1081
|
response,
|
|
1026
|
-
|
|
1027
|
-
return _regeneratorRuntime().wrap(function
|
|
1028
|
-
while (1) switch (
|
|
1082
|
+
_args22 = arguments;
|
|
1083
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1084
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1029
1085
|
case 0:
|
|
1030
|
-
params =
|
|
1086
|
+
params = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
|
|
1031
1087
|
debugger;
|
|
1032
|
-
|
|
1088
|
+
_context22.prev = 2;
|
|
1033
1089
|
// Add the authToken to the headers
|
|
1034
1090
|
headers = {
|
|
1035
1091
|
authtoken: this.authtoken
|
|
1036
1092
|
}; // Make the GET request using Axios
|
|
1037
|
-
|
|
1093
|
+
_context22.next = 6;
|
|
1038
1094
|
return this.axios.get(endpoint, {
|
|
1039
1095
|
params: params,
|
|
1040
1096
|
headers: headers
|
|
1041
1097
|
});
|
|
1042
1098
|
case 6:
|
|
1043
|
-
response =
|
|
1099
|
+
response = _context22.sent;
|
|
1044
1100
|
if (!(response.data.ok === false)) {
|
|
1045
|
-
|
|
1101
|
+
_context22.next = 9;
|
|
1046
1102
|
break;
|
|
1047
1103
|
}
|
|
1048
|
-
return
|
|
1104
|
+
return _context22.abrupt("return", this._handleError(response));
|
|
1049
1105
|
case 9:
|
|
1050
|
-
return
|
|
1106
|
+
return _context22.abrupt("return", response.data);
|
|
1051
1107
|
case 12:
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
return
|
|
1108
|
+
_context22.prev = 12;
|
|
1109
|
+
_context22.t0 = _context22["catch"](2);
|
|
1110
|
+
return _context22.abrupt("return", this._handleError(_context22.t0));
|
|
1055
1111
|
case 15:
|
|
1056
1112
|
case "end":
|
|
1057
|
-
return
|
|
1113
|
+
return _context22.stop();
|
|
1058
1114
|
}
|
|
1059
|
-
},
|
|
1115
|
+
}, _callee22, this, [[2, 12]]);
|
|
1060
1116
|
}));
|
|
1061
1117
|
function get(_x16) {
|
|
1062
1118
|
return _get.apply(this, arguments);
|
|
@@ -1079,42 +1135,42 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1079
1135
|
}, {
|
|
1080
1136
|
key: "post",
|
|
1081
1137
|
value: (function () {
|
|
1082
|
-
var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1138
|
+
var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(endpoint) {
|
|
1083
1139
|
var data,
|
|
1084
1140
|
headers,
|
|
1085
1141
|
response,
|
|
1086
|
-
|
|
1087
|
-
return _regeneratorRuntime().wrap(function
|
|
1088
|
-
while (1) switch (
|
|
1142
|
+
_args23 = arguments;
|
|
1143
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1144
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1089
1145
|
case 0:
|
|
1090
|
-
data =
|
|
1091
|
-
|
|
1146
|
+
data = _args23.length > 1 && _args23[1] !== undefined ? _args23[1] : {};
|
|
1147
|
+
_context23.prev = 1;
|
|
1092
1148
|
// Add the authToken to the headers
|
|
1093
1149
|
headers = {
|
|
1094
1150
|
authtoken: this.authtoken
|
|
1095
1151
|
}; // Make the POST request using Axios
|
|
1096
|
-
|
|
1152
|
+
_context23.next = 5;
|
|
1097
1153
|
return this.axios.post(endpoint, data, {
|
|
1098
1154
|
headers: headers
|
|
1099
1155
|
});
|
|
1100
1156
|
case 5:
|
|
1101
|
-
response =
|
|
1157
|
+
response = _context23.sent;
|
|
1102
1158
|
if (!(response.data.ok === false)) {
|
|
1103
|
-
|
|
1159
|
+
_context23.next = 8;
|
|
1104
1160
|
break;
|
|
1105
1161
|
}
|
|
1106
|
-
return
|
|
1162
|
+
return _context23.abrupt("return", this._handleError(response));
|
|
1107
1163
|
case 8:
|
|
1108
|
-
return
|
|
1164
|
+
return _context23.abrupt("return", response.data);
|
|
1109
1165
|
case 11:
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
return
|
|
1166
|
+
_context23.prev = 11;
|
|
1167
|
+
_context23.t0 = _context23["catch"](1);
|
|
1168
|
+
return _context23.abrupt("return", this._handleError(_context23.t0));
|
|
1113
1169
|
case 14:
|
|
1114
1170
|
case "end":
|
|
1115
|
-
return
|
|
1171
|
+
return _context23.stop();
|
|
1116
1172
|
}
|
|
1117
|
-
},
|
|
1173
|
+
}, _callee23, this, [[1, 11]]);
|
|
1118
1174
|
}));
|
|
1119
1175
|
function post(_x17) {
|
|
1120
1176
|
return _post.apply(this, arguments);
|
package/dist/esm/rbt_api.js
CHANGED
|
@@ -215,6 +215,10 @@ export default class RbtApi {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
async refreshAuthToken(authtoken) {
|
|
218
|
+
if (!this.appServiceHost) {
|
|
219
|
+
console.warn('appServiceHost not initialized');
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
218
222
|
try {
|
|
219
223
|
const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
|
|
220
224
|
debugger;
|
|
@@ -399,7 +403,12 @@ export default class RbtApi {
|
|
|
399
403
|
|
|
400
404
|
/**
|
|
401
405
|
* Makes a POST request to a specific endpoint to run a task and handle progress updates.
|
|
402
|
-
*
|
|
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
|
+
*
|
|
403
412
|
* @param {Object} params - The parameters to be sent in the POST request.
|
|
404
413
|
* @param {Object} callbacks - An object containing callback functions for progress and error handling.
|
|
405
414
|
*
|
|
@@ -414,7 +423,8 @@ export default class RbtApi {
|
|
|
414
423
|
const {
|
|
415
424
|
onProgress,
|
|
416
425
|
onError,
|
|
417
|
-
|
|
426
|
+
onStopped,
|
|
427
|
+
onDone
|
|
418
428
|
} = callbacks;
|
|
419
429
|
try {
|
|
420
430
|
const response = await this.post('/task_service/runChain', params);
|
|
@@ -436,17 +446,21 @@ export default class RbtApi {
|
|
|
436
446
|
}
|
|
437
447
|
|
|
438
448
|
// If the task is still in progress, start polling for updates
|
|
439
|
-
if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED') {
|
|
449
|
+
if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED' || status === 'STOPPING') {
|
|
440
450
|
this.pollTaskProgress(jobId, callbacks);
|
|
441
451
|
}
|
|
442
452
|
if (status === 'ERROR' && onError) {
|
|
443
453
|
// Provide the current progress to the callback function
|
|
444
454
|
onError(response);
|
|
445
455
|
}
|
|
446
|
-
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) {
|
|
447
461
|
// Provide the current progress to the callback function
|
|
448
462
|
console.log('Finish (request) ', response);
|
|
449
|
-
|
|
463
|
+
onDone(response);
|
|
450
464
|
}
|
|
451
465
|
return {
|
|
452
466
|
ok,
|
|
@@ -469,6 +483,18 @@ export default class RbtApi {
|
|
|
469
483
|
};
|
|
470
484
|
}
|
|
471
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
|
+
}
|
|
472
498
|
|
|
473
499
|
/**
|
|
474
500
|
* Polls the progress of a long-running task.
|
|
@@ -484,7 +510,7 @@ export default class RbtApi {
|
|
|
484
510
|
const {
|
|
485
511
|
onProgress,
|
|
486
512
|
onError,
|
|
487
|
-
|
|
513
|
+
onDone
|
|
488
514
|
} = callbacks;
|
|
489
515
|
try {
|
|
490
516
|
const checkProgress = async () => {
|
|
@@ -493,10 +519,10 @@ export default class RbtApi {
|
|
|
493
519
|
});
|
|
494
520
|
|
|
495
521
|
// If the task is still in progress, start polling for updates
|
|
496
|
-
if (response.status === 'DONE' &&
|
|
522
|
+
if (response.status === 'DONE' && onDone) {
|
|
497
523
|
// Provide the current progress to the callback function
|
|
498
524
|
console.log('Finish (progress) ', response);
|
|
499
|
-
|
|
525
|
+
onDone(response);
|
|
500
526
|
}
|
|
501
527
|
if (response.status === 'ERROR' && onError) {
|
|
502
528
|
// Provide the current progress to the callback function
|
package/package.json
CHANGED
package/src/rbt_api.js
CHANGED
|
@@ -275,6 +275,11 @@ export default class RbtApi {
|
|
|
275
275
|
|
|
276
276
|
async refreshAuthToken(authtoken){
|
|
277
277
|
|
|
278
|
+
if(!this.appServiceHost){
|
|
279
|
+
console.warn('appServiceHost not initialized');
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
|
|
278
283
|
try {
|
|
279
284
|
|
|
280
285
|
const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
|
|
@@ -456,7 +461,12 @@ export default class RbtApi {
|
|
|
456
461
|
|
|
457
462
|
/**
|
|
458
463
|
* Makes a POST request to a specific endpoint to run a task and handle progress updates.
|
|
459
|
-
*
|
|
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
|
+
*
|
|
460
470
|
* @param {Object} params - The parameters to be sent in the POST request.
|
|
461
471
|
* @param {Object} callbacks - An object containing callback functions for progress and error handling.
|
|
462
472
|
*
|
|
@@ -468,7 +478,7 @@ export default class RbtApi {
|
|
|
468
478
|
* }
|
|
469
479
|
*/
|
|
470
480
|
async runTask(params = {}, callbacks = {}) {
|
|
471
|
-
const { onProgress, onError,
|
|
481
|
+
const { onProgress, onError, onStopped, onDone } = callbacks;
|
|
472
482
|
|
|
473
483
|
try {
|
|
474
484
|
const response = await this.post('/task_service/runChain', params);
|
|
@@ -484,17 +494,21 @@ export default class RbtApi {
|
|
|
484
494
|
}
|
|
485
495
|
|
|
486
496
|
// If the task is still in progress, start polling for updates
|
|
487
|
-
if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED') {
|
|
497
|
+
if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED' || status === 'STOPPING') {
|
|
488
498
|
this.pollTaskProgress(jobId, callbacks);
|
|
489
499
|
}
|
|
490
500
|
if (status === 'ERROR' && onError){
|
|
491
501
|
// Provide the current progress to the callback function
|
|
492
502
|
onError(response);
|
|
493
503
|
}
|
|
494
|
-
if (status === '
|
|
504
|
+
if (status === 'STOPPED' && onError){
|
|
505
|
+
// Provide the current progress to the callback function
|
|
506
|
+
onStopped(response);
|
|
507
|
+
}
|
|
508
|
+
if (status === 'DONE' && onDone){
|
|
495
509
|
// Provide the current progress to the callback function
|
|
496
|
-
|
|
497
|
-
|
|
510
|
+
console.log('Finish (request) ',response);
|
|
511
|
+
onDone(response);
|
|
498
512
|
}
|
|
499
513
|
|
|
500
514
|
return { ok, jobId, status, message, output };
|
|
@@ -511,6 +525,23 @@ export default class RbtApi {
|
|
|
511
525
|
}
|
|
512
526
|
}
|
|
513
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
|
+
|
|
514
545
|
|
|
515
546
|
/**
|
|
516
547
|
* Polls the progress of a long-running task.
|
|
@@ -523,16 +554,16 @@ export default class RbtApi {
|
|
|
523
554
|
* the task is completed or an error occurs.
|
|
524
555
|
*/
|
|
525
556
|
async pollTaskProgress(jobId, callbacks) {
|
|
526
|
-
const { onProgress, onError,
|
|
557
|
+
const { onProgress, onError, onDone } = callbacks;
|
|
527
558
|
try {
|
|
528
559
|
const checkProgress = async () => {
|
|
529
560
|
const response = await this.get(`/task_service/pollChainProgress`, { jobId: jobId });
|
|
530
561
|
|
|
531
562
|
// If the task is still in progress, start polling for updates
|
|
532
|
-
if (response.status === 'DONE' &&
|
|
563
|
+
if (response.status === 'DONE' && onDone){
|
|
533
564
|
// Provide the current progress to the callback function
|
|
534
565
|
console.log('Finish (progress) ',response);
|
|
535
|
-
|
|
566
|
+
onDone(response);
|
|
536
567
|
}
|
|
537
568
|
if (response.status === 'ERROR' && onError){
|
|
538
569
|
// Provide the current progress to the callback function
|