diff --git a/src/components/backend-ai-resource-broker.ts b/src/components/backend-ai-resource-broker.ts index 51161a8a5f..4c3dc7ab28 100644 --- a/src/components/backend-ai-resource-broker.ts +++ b/src/components/backend-ai-resource-broker.ts @@ -349,6 +349,10 @@ export default class BackendAiResourceBroker extends BackendAIPage { * */ async _refreshResourcePolicy() { + if (!globalThis.backendaiclient) { + // To prevent a silent failure when the client is not ready in aggregating resources. + return Promise.resolve(false); + } if (Date.now() - this.lastResourcePolicyQueryTime < 2000) { return Promise.resolve(false); } @@ -482,7 +486,7 @@ export default class BackendAiResourceBroker extends BackendAIPage { * @param {string} from - set the value for debugging purpose. */ async _aggregateCurrentResource(from = '') { - if (this.aggregate_updating) { + if (!globalThis.backendaiclient || this.aggregate_updating) { return Promise.resolve(false); } if (Date.now() - this.lastQueryTime < 1000) { diff --git a/src/components/backend-ai-resource-monitor.ts b/src/components/backend-ai-resource-monitor.ts index a55a6a8b20..ff94230fe1 100644 --- a/src/components/backend-ai-resource-monitor.ts +++ b/src/components/backend-ai-resource-monitor.ts @@ -532,7 +532,16 @@ export default class BackendAiResourceMonitor extends BackendAIPage { } return this.resourceBroker ._refreshResourcePolicy() - .then(() => { + .then((resolvedValue) => { + if (resolvedValue === false) { + setTimeout(() => { + // Retry to get the concurrency_max after a while if resource broker + // is not ready. When the timeout is 2000, it delays the display of + // other resource's allocation status. I don't know why, but I just + // set it to 2500. + this._refreshResourcePolicy(); + }, 2500); + } this.concurrency_used = this.resourceBroker.concurrency_used; // this.userResourceLimit = this.resourceBroker.userResourceLimit; this.concurrency_max =