My Launch method is designed to start an engine by taking parameters and returning the instance name once started. After that, I need to periodically query another service every 2 seconds to check if the status has changed to either "Succeeded" or "Failed". I attempted to use a do while loop within the first subscription, but it did not work as expected.
instanceStatus: string = "Initialized";
instanceName:string = "InstanceName";
Launch(sessionId: string, projectName: string, f: string[]) {
this.service.Launch(sessionId, projectName, this.f)
.pipe(first())
.subscribe(
instanceName => {
localStorage.setItem('instanceName', instanceName);
this.instanceName = instanceName;
setTimeout(() => {
do {
this.service.getEngineStatus(this.instanceName)
.pipe(first())
.subscribe(
status => {
this.instanceStatus = status;
console.log(status);
console.log(this.instanceStatus);
this.loadingService.showSpinner({ text: 'Modeling is running...' });
if (this.instanceStatus === "Succeeded") {
this.messageService.add({ severity: Severity.Success, summary: 'Fault modeling completed', detail: 'Via MessageService' });
this.messageService.clear();
}
}
);
} while (this.instanceStatus !== "Succeeded")
}, 2000);
}
);
}
getEngineStatus(instanceName:string): Observable<string> {
this.serviceUrl = URL + `?instance=` + instanceName;
return this._http.get<string>(this.serviceUrl);
}