Skip to content

Commit 201e531

Browse files
committed
osparc.store.Jobs
1 parent a29ada7 commit 201e531

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

services/static-webserver/client/source/class/osparc/desktop/MainPage.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ qx.Class.define("osparc.desktop.MainPage", {
6969
preloadPromises.push(osparc.store.Tags.getInstance().fetchTags());
7070
preloadPromises.push(osparc.store.Products.getInstance().fetchUiConfig());
7171
preloadPromises.push(osparc.store.PollTasks.getInstance().fetchTasks());
72+
if (osparc.utils.Utils.isDevelopmentPlatform()) {
73+
preloadPromises.push(osparc.store.Jobs.getInstance().fetchJobs());
74+
}
7275
Promise.all(preloadPromises)
7376
.then(() => {
7477
const mainStack = this.__createMainStack();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2025 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.store.Jobs", {
19+
extend: qx.core.Object,
20+
type: "singleton",
21+
22+
properties: {
23+
jobs: {
24+
check: "Array",
25+
init: [],
26+
nullable: true,
27+
event: "changeJobs"
28+
}
29+
},
30+
31+
members: {
32+
fetchJobs: function() {
33+
return osparc.data.Resources.get("jobs")
34+
.then(jobsData => {
35+
jobsData.forEach(jobData => {
36+
const interval = 1000;
37+
this.addJob(jobData, interval);
38+
});
39+
})
40+
.catch(err => console.error(err));
41+
},
42+
43+
addJob: function(jobData, interval = 1000) {
44+
const jobs = this.getJobs();
45+
const index = jobs.findIndex(t => t.getJobId() === jobData["job_id"]);
46+
if (index === -1) {
47+
const job = new osparc.data.Job(jobData, interval);
48+
jobs.push(job);
49+
return job;
50+
}
51+
return null;
52+
},
53+
54+
createJob: function(fetchPromise, interval) {
55+
return new Promise((resolve, reject) => {
56+
fetchPromise
57+
.then(jobData => {
58+
if ("status_href" in jobData) {
59+
const job = this.addJob(jobData, interval);
60+
resolve(job);
61+
} else {
62+
throw Error("Status missing");
63+
}
64+
})
65+
.catch(err => reject(err));
66+
});
67+
},
68+
69+
removeJobs: function() {
70+
const jobs = this.getJobs();
71+
jobs.forEach(job => job.dispose());
72+
},
73+
}
74+
});

0 commit comments

Comments
 (0)