Compare commits

...

1 Commits

Author SHA1 Message Date
Pierre Brunet
88495d763d feat: aggregate errors in backup runners 2026-05-20 17:10:43 +02:00
3 changed files with 31 additions and 1 deletions

View File

@@ -71,6 +71,7 @@ export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
const queue = new Set(vmsUuids)
const taskByVmId = {}
const nTriesByVmId = {}
const vmErrors = []
const handleVm = vmUuid => {
if (nTriesByVmId[vmUuid] === undefined) {
@@ -126,6 +127,7 @@ export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
return task.success(result)
}
if (isLastRun) {
vmErrors.push(taskError)
return task.failure(taskError)
}
// don't end the task
@@ -148,6 +150,8 @@ export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
await asyncMapSettled(vmIds, _handleVm)
}
this._throwVmErrors(vmErrors)
}
)
}

View File

@@ -98,6 +98,7 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
const queue = new Set(vmIds)
const taskByVmId = {}
const nTriesByVmId = {}
const vmErrors = []
const handleVm = vmUuid => {
const getVmTask = () => {
@@ -175,11 +176,19 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
} else {
// ending the task with error or not ending the task
vmBackupFailed(taskError, task)
if (isLastRun) {
vmErrors.push(taskError)
}
}
})
.catch(noop) // errors are handled by logs
}),
error => vmBackupFailed(error, getVmTask())
error => {
vmBackupFailed(error, getVmTask())
if (isLastRun) {
vmErrors.push(error)
}
}
)
}
const { concurrency } = settings
@@ -191,6 +200,8 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
await asyncMapSettled(vmIds, _handleVm)
}
this._throwVmErrors(vmErrors)
}
)
}

View File

@@ -11,7 +11,22 @@ export const DEFAULT_SETTINGS = {
reportWhen: 'failure',
}
export class AggregateError extends Error {
constructor(errors, message) {
super(message)
this.errors = errors
}
}
export const Abstract = class AbstractRunner {
_throwVmErrors(errors) {
if (errors.length === 1) {
throw errors[0]
} else if (errors.length > 1) {
throw new AggregateError(errors, `${errors.length} VMs failed`)
}
}
constructor({ config, getAdapter, getConnectedRecord, job, schedule }) {
this._config = config
this._getRecord = getConnectedRecord