handle instance action update by process id

This commit is contained in:
Arthur Lu 2022-12-18 20:32:05 -08:00
parent d03292a29c
commit aa4ea3e0de

View File

@ -78,25 +78,40 @@ class Instance extends HTMLElement {
powerButton.src = "images/actions/loading.svg"; powerButton.src = "images/actions/loading.svg";
powerButton.alt = `instance is ${targetActionDesc}`; 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) { while (true) {
let data = await request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/current`); let taskStatus = await request(`/nodes/${this.node}/tasks/${task.data}/status`);
if(data.data.status === targetStatus) { if(taskStatus.data.status === "stopped" && taskStatus.data.exitstatus === "OK") {
this.status = targetStatus;
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;
break; break;
} }
await waitFor(1000); 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);
}
} }
this.status = targetStatus;
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;
} }
}); });