improve power management status update
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
12ec4f1ee4
commit
e7973db190
@ -1,7 +1,5 @@
|
|||||||
import {requestPVE, goToPage, instances} from "./utils.js";
|
import {requestPVE, goToPage, instances} from "./utils.js";
|
||||||
|
|
||||||
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
|
|
||||||
|
|
||||||
export class Instance extends HTMLElement {
|
export class Instance extends HTMLElement {
|
||||||
constructor () {
|
constructor () {
|
||||||
super();
|
super();
|
||||||
@ -91,33 +89,24 @@ export class Instance extends HTMLElement {
|
|||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
|
|
||||||
let task;
|
let result = await requestPVE(`/nodes/${this.node.name}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node.name, vmid: this.vmid});
|
||||||
|
|
||||||
try {
|
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
|
||||||
task = await requestPVE(`/nodes/${this.node.name}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node.name, vmid: this.vmid});
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
this.status = prevStatus;
|
|
||||||
this.update();
|
|
||||||
this.actionLock = false;
|
|
||||||
console.error(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
let taskStatus = await requestPVE(`/nodes/${this.node.name}/tasks/${task.data}/status`);
|
let taskStatus = await requestPVE(`/nodes/${this.node.name}/tasks/${result.data}/status`);
|
||||||
if(taskStatus.data.status === "stopped" && taskStatus.data.exitstatus === "OK") { // task stopped and was successful
|
if(taskStatus.data.status === "stopped" && taskStatus.data.exitstatus === "OK") { // task stopped and was successful
|
||||||
this.status = targetStatus;
|
this.status = targetStatus;
|
||||||
this.update();
|
this.update();
|
||||||
this.actionLock = false;
|
this.actionLock = false;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
else if (taskStatus.data.status === "stopped") { // task stopped but was not successful
|
else if (taskStatus.data.status === "stopped") { // task stopped but was not successful
|
||||||
this.status = prevStatus;
|
this.status = prevStatus;
|
||||||
console.error(`attempted to ${targetAction} ${this.vmid} but process returned stopped:${taskStatus.data.exitstatus}`);
|
console.error(`attempted to ${targetAction} ${this.vmid} but process returned stopped:${result.data.exitstatus}`);
|
||||||
this.update();
|
this.update();
|
||||||
this.actionLock = false;
|
this.actionLock = false;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
else{ // task has not stopped
|
else{ // task has not stopped
|
||||||
await waitFor(1000);
|
await waitFor(1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user