Skip to content

Commit c4ed47b

Browse files
committed
refactor
1 parent 3bd7f4a commit c4ed47b

File tree

2 files changed

+50
-41
lines changed

2 files changed

+50
-41
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ qx.Class.define("osparc.data.Resources", {
334334
},
335335
}
336336
},
337+
"runPipeline": {
338+
useCache: false,
339+
endpoints: {
340+
startPipeline: {
341+
method: "POST",
342+
url: statics.API + "/computations/{studyId}:start"
343+
},
344+
}
345+
},
337346
"jobs": {
338347
useCache: false, // handled in osparc.store.Jobs
339348
endpoints: {

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -569,64 +569,64 @@ qx.Class.define("osparc.desktop.StudyEditor", {
569569
return;
570570
}
571571

572-
this.getStudy().setPipelineRunning(true);
573572
this.updateStudyDocument()
574573
.then(() => {
575574
this.__requestStartPipeline(this.getStudy().getUuid(), partialPipeline);
576575
})
577576
.catch(() => {
578577
this.getStudyLogger().error(null, "Run failed");
579-
this.getStudy().setPipelineRunning(false);
580578
});
581579
},
582580

583581
__requestStartPipeline: function(studyId, partialPipeline = [], forceRestart = false) {
584-
const url = "/computations/" + encodeURIComponent(studyId) + ":start";
585-
const req = new osparc.io.request.ApiRequest(url, "POST");
586-
req.addListener("success", this.__onPipelineSubmitted, this);
587-
req.addListener("error", () => {
588-
this.getStudyLogger().error(null, "Error submitting pipeline");
589-
this.getStudy().setPipelineRunning(false);
590-
}, this);
591-
req.addListener("fail", async e => {
592-
if (e.getTarget().getStatus() == "409") {
593-
this.getStudyLogger().error(null, "Pipeline is already running");
594-
} else if (e.getTarget().getStatus() == "422") {
595-
this.getStudyLogger().info(null, "The pipeline is up-to-date");
596-
const msg = this.tr("The pipeline is up-to-date. Do you want to re-run it?");
597-
const win = new osparc.ui.window.Confirmation(msg).set({
598-
caption: this.tr("Re-run"),
599-
confirmText: this.tr("Run"),
600-
confirmAction: "create"
601-
});
602-
win.center();
603-
win.open();
604-
win.addListener("close", () => {
605-
if (win.getConfirmed()) {
606-
this.__requestStartPipeline(studyId, partialPipeline, true);
607-
}
608-
}, this);
609-
} else if (e.getTarget().getStatus() == "402") {
610-
const msg = await e.getTarget().getResponse().error.errors[0].message;
611-
osparc.FlashMessenger.logAs(msg, "WARNING");
612-
} else {
613-
this.getStudyLogger().error(null, "Unsuccessful pipeline submission");
614-
}
615-
this.getStudy().setPipelineRunning(false);
616-
}, this);
582+
this.getStudy().setPipelineRunning(true);
617583

618-
const requestData = {
619-
"subgraph": partialPipeline,
620-
"force_restart": forceRestart
621-
};
622-
req.setRequestData(requestData);
623-
req.send();
624584
if (partialPipeline.length) {
625585
this.getStudyLogger().info(null, "Starting partial pipeline");
626586
} else {
627587
this.getStudyLogger().info(null, "Starting pipeline");
628588
}
629589

590+
const params = {
591+
url: {
592+
"studyId": studyId
593+
},
594+
data: {
595+
"subgraph": partialPipeline,
596+
"force_restart": forceRestart,
597+
}
598+
};
599+
osparc.data.Resources.fetch("runPipeline", "startPipeline", params)
600+
.then(() => this.__onPipelineSubmitted)
601+
.catch(err => {
602+
let msg = err.message;
603+
const errStatus = err.status;
604+
if (errStatus == "409") {
605+
this.getStudyLogger().error(null, "Pipeline is already running");
606+
} else if (errStatus == "422") {
607+
this.getStudyLogger().info(null, "The pipeline is up-to-date");
608+
msg = this.tr("The pipeline is up-to-date. Do you want to re-run it?");
609+
const win = new osparc.ui.window.Confirmation(msg).set({
610+
caption: this.tr("Re-run"),
611+
confirmText: this.tr("Run"),
612+
confirmAction: "create"
613+
});
614+
win.center();
615+
win.open();
616+
win.addListener("close", () => {
617+
if (win.getConfirmed()) {
618+
this.__requestStartPipeline(studyId, partialPipeline, true);
619+
}
620+
}, this);
621+
} else if (err.status == "402") {
622+
osparc.FlashMessenger.logAs(msg, "WARNING");
623+
} else {
624+
osparc.FlashMessenger.logAs(msg, "WARNING");
625+
this.getStudyLogger().error(null, "Unsuccessful pipeline submission");
626+
}
627+
this.getStudy().setPipelineRunning(false);
628+
});
629+
630630
return true;
631631
},
632632

0 commit comments

Comments
 (0)