Skip to content

Commit d9f8054

Browse files
committed
refactor
1 parent 8442e43 commit d9f8054

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,31 +426,36 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
426426
this._loadingResourcesBtn.setVisibility("visible");
427427
const filterData = this._searchBarFilter.getFilterData();
428428
const text = filterData.text ? encodeURIComponent(filterData.text) : "";
429-
const streamPromise = osparc.store.Data.getInstance().searchFiles(text);
430-
let stream = null;
431-
const pollingInterval = 2000;
432-
osparc.store.StreamTasks.getInstance().getStreamTask("files_search", text, streamPromise, pollingInterval)
433-
.then(strm => {
434-
stream = strm;
435-
console.log("Streaming files search...", stream);
436-
return stream.fetchStream()
437-
})
429+
const existingStream = osparc.store.StreamTasks.getInstance().getStreamTask("files_search", text);
430+
if (existingStream) {
431+
this.__fetchFilesFromStream(existingStream);
432+
} else {
433+
const streamPromise = osparc.store.Data.getInstance().searchFiles(text);
434+
const pollingInterval = 2000;
435+
osparc.store.StreamTasks.getInstance().createStreamTask("files_search", text, streamPromise, pollingInterval)
436+
.then(newStream => this.__fetchFilesFromStream(newStream));
437+
}
438+
},
439+
440+
__fetchFilesFromStream: function(stream) {
441+
stream.fetchStream()
438442
.then(streamData => {
439443
const items = streamData["data"]["items"] || [];
440444
if (items.length) {
441445
this.__setFilesToList(items);
442446
}
443447
const end = streamData["data"]["end"] || false;
444-
if (end === false && items.length === 0 && stream) {
448+
if (end === false || items.length === 0) {
445449
// nothing to stream yet, try again later
450+
const pollingInterval = 2000;
446451
setTimeout(() => this.__reloadFiles(), pollingInterval);
447452
}
448453
})
449454
.catch(err => console.log(err))
450455
.finally(() => {
451456
this._loadingResourcesBtn.setFetching(false);
452457
/*
453-
if (stream && stream.isEnd() === false) {
458+
if (stream.isEnd() === false) {
454459
setTimeout(() => this.__reloadFiles(), 500);
455460
}
456461
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ qx.Class.define("osparc.data.PollTask", {
131131

132132
__pollTaskState: function() {
133133
const statusPath = this.self().extractPathname(this.getStatusHref());
134+
// OM remove
135+
return;
134136
fetch(statusPath)
135137
.then(resp => {
136138
if (this.__aborting || this.getDone()) {

services/static-webserver/client/source/class/osparc/store/StreamTasks.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,33 @@ qx.Class.define("osparc.store.StreamTasks", {
2727
}
2828
},
2929

30-
members: {
31-
getStreamTask: function(action, params, streamPromise, interval) {
32-
const internalId = action + "_" + JSON.stringify(params);
33-
const task = this.__getStreamTask(internalId);
34-
if (task) {
35-
console.log("Reusing existing stream task:", internalId);
36-
return Promise.resolve(task);
37-
}
38-
return this.__createStreamTask(internalId, streamPromise, interval)
39-
.then(streamTask => {
40-
console.log("Creating new stream task:", internalId);
41-
return streamTask;
42-
})
43-
.catch(err => Promise.reject(err));
30+
statics: {
31+
actionToInternalId: function(action, params) {
32+
return action + "_" + JSON.stringify(params);
4433
},
34+
},
4535

46-
__createStreamTask: function(internalId, streamPromise, interval) {
36+
members: {
37+
createStreamTask: function(action, params, streamPromise, interval) {
4738
return streamPromise
4839
.then(streamData => {
4940
console.log("Stream data received:", streamData);
5041
if (!("stream_href" in streamData)) {
5142
throw new Error("Stream href missing");
5243
}
53-
return this.__addStreamTask(internalId, streamData, interval);
44+
return this.__addStreamTask(action, params, streamData, interval);
5445
})
5546
.catch(err => Promise.reject(err));
5647
},
5748

58-
__getStreamTask: function(internalId) {
49+
getStreamTask: function(action, params) {
50+
const internalId = osparc.store.StreamTasks.actionToInternalId(action, params);
5951
const tasks = this.getTasks();
6052
return tasks[internalId] || null;
6153
},
6254

63-
__addStreamTask: function(internalId, streamData, interval) {
64-
const task = this.__getStreamTask(internalId);
65-
if (task) {
66-
return task;
67-
}
68-
55+
__addStreamTask: function(action, params, streamData, interval) {
56+
const internalId = osparc.store.StreamTasks.actionToInternalId(action, params);
6957
const stream = new osparc.data.StreamTask(streamData, interval);
7058
// stream.addListener("resultReceived", () => this.__removeStreamTask(stream), this);
7159
stream.addListener("taskAborted", () => this.__removeStreamTask(stream), this);

0 commit comments

Comments
 (0)