Skip to content

Commit

Permalink
replaced Promise.all by asyncEach, limit blockedOperations to migrati…
Browse files Browse the repository at this point in the history
…on related
  • Loading branch information
stephane-m-dev committed Nov 26, 2024
1 parent c659546 commit a53664d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/xo-server/src/api/host.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { incorrectState } from 'xo-common/api-errors.js'
import { X509Certificate } from 'node:crypto'

import backupGuard from './_backupGuard.mjs'
import { asyncEach } from '@vates/async-each'

const CERT_PUBKEY_MIN_SIZE = 2048
const IPMI_CACHE_TTL = 6e4
Expand All @@ -23,17 +24,21 @@ export async function setMaintenanceMode({ host, maintenance, vmsToForceMigrate
const xapi = this.getXapi(host)

if (vmsToForceMigrate) {
await Promise.all(
vmsToForceMigrate.map(async vmUuid => {
await asyncEach(
vmsToForceMigrate,
async vmUuid => {
const record = await xapi.getRecordByUuid('VM', vmUuid)
const ref = record.$ref
const blockedOperations = record.blocked_operations
await Promise.all(
Object.keys(blockedOperations).map(
async operation => await xapi.call('VM.remove_from_blocked_operations', ref, operation)
)
Object.keys(blockedOperations)
.filter(operation => ['pool_migrate', 'migrate_send'].includes(operation))
.map(async operation => await xapi.call('VM.remove_from_blocked_operations', ref, operation))
)
})
},
{
concurrency: 4,
}
)
}

Expand Down

0 comments on commit a53664d

Please sign in to comment.