handle instance action update by process id

This commit is contained in:
Arthur Lu 2022-12-18 20:32:05 -08:00
parent 8d4c5e122a
commit bbf94c983d

View File

@ -78,16 +78,11 @@ class Instance extends HTMLElement {
powerButton.src = "images/actions/loading.svg";
powerButton.alt = `instance is ${targetActionDesc}`;
await request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node, vmid: this.vmid});
let task = await request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node, vmid: this.vmid});
while (true) {
let data = await request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/current`);
if(data.data.status === targetStatus) {
break;
}
await waitFor(1000);
}
let taskStatus = await request(`/nodes/${this.node}/tasks/${task.data}/status`);
if(taskStatus.data.status === "stopped" && taskStatus.data.exitstatus === "OK") {
this.status = targetStatus;
typeImg.src = `images/instances/${this.type}/${this.status}.svg`;
@ -97,6 +92,26 @@ class Instance extends HTMLElement {
powerButton.alt = this.status === "running" ? "shutdown instance" : "start instance";
this.actionLock = false;
break;
}
else if (taskStatus.data.status === "stopped") { // stopped but not OK -> instance did not change state
typeImg.src = `images/instances/${this.type}/${this.status}.svg`;
typeImg.alt = `${this.status} instance`;
powerButton.src = this.status === "running" ? "images/actions/stop.svg" : "images/actions/start.svg";
powerButton.alt = this.status === "running" ? "shutdown instance" : "start instance";
this.actionLock = false;
console.error(`attempted to ${targetAction} ${this.vmid} but process returned stopped:${taskStatus.data.exitstatus}`);
break;
}
else{
await waitFor(1000);
}
}
}
});