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,16 +78,11 @@ 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") {
break;
}
await waitFor(1000);
}
this.status = targetStatus; this.status = targetStatus;
typeImg.src = `images/instances/${this.type}/${this.status}.svg`; 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"; powerButton.alt = this.status === "running" ? "shutdown instance" : "start instance";
this.actionLock = false; 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);
}
}
} }
}); });