Skip to content

Commit 2bcb4de

Browse files
committed
timeout and timeoutRetries
1 parent 2938a9e commit 2bcb4de

File tree

1 file changed

+14
-2
lines changed
  • services/static-webserver/client/source/class/osparc/data

1 file changed

+14
-2
lines changed

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ qx.Class.define("osparc.data.Resources", {
12471247
* @param {String} resource Name of the resource as defined in the static property 'resources'.
12481248
* @param {String} endpoint Name of the endpoint. Several endpoints can be defined for each resource.
12491249
* @param {Object} params Object containing the parameters for the url and for the body of the request, under the properties 'url' and 'data', respectively.
1250-
* @param {Object} options Collections of options (pollTask, resolveWResponse)
1250+
* @param {Object} options Collections of options (pollTask, resolveWResponse, timeout, timeoutRetries)
12511251
*/
12521252
fetch: function(resource, endpoint, params = {}, options = {}) {
12531253
return new Promise((resolve, reject) => {
@@ -1257,11 +1257,16 @@ qx.Class.define("osparc.data.Resources", {
12571257

12581258
const resourceDefinition = this.self().resources[resource];
12591259
const res = new osparc.io.rest.Resource(resourceDefinition.endpoints);
1260-
12611260
if (!res.includesRoute(endpoint)) {
12621261
reject(Error(`Error while fetching ${resource}: the endpoint is not defined`));
12631262
}
12641263

1264+
if (options.timeout) {
1265+
res.configureRequest(request => {
1266+
request.setTimeout(options.timeout);
1267+
});
1268+
}
1269+
12651270
res.addListenerOnce(endpoint + "Success", e => {
12661271
const response = e.getRequest().getResponse();
12671272
const endpointDef = resourceDefinition.endpoints[endpoint];
@@ -1301,6 +1306,13 @@ qx.Class.define("osparc.data.Resources", {
13011306
}, this);
13021307

13031308
res.addListenerOnce(endpoint + "Error", e => {
1309+
if (e.getPhase() === "timeout") {
1310+
if (options.timeout && options.timeoutRetries) {
1311+
options.timeoutRetries--;
1312+
this.fetch(resource, endpoint, params, options);
1313+
}
1314+
}
1315+
13041316
let message = null;
13051317
let status = null;
13061318
if (e.getData().error) {

0 commit comments

Comments
 (0)