feat(backups/Backup): pass directly getConnectedRecord (#5614)

This should make it easier to interface with xo-server.
This commit is contained in:
Julien Fontanet
2021-02-24 17:25:46 +01:00
committed by GitHub
parent 11801f306c
commit 4eb9aa9ccb
2 changed files with 12 additions and 17 deletions

View File

@@ -28,17 +28,15 @@ exports.Backup = class Backup {
constructor({
config,
getAdapter,
getConnectedXapi,
getConnectedRecord,
job,
recordToXapi,
remotes,
schedule,
}) {
this._config = config
this._getConnectedXapi = getConnectedXapi
this._getRecord = getConnectedRecord
this._job = job
this._recordToXapi = recordToXapi
this._remotes = remotes
this._schedule = schedule
@@ -218,15 +216,4 @@ exports.Backup = class Backup {
}
)
}
_getRecord = Disposable.factory(this._getRecord)
async *_getRecord(type, uuid) {
const xapiId = this._recordToXapi[uuid]
if (xapiId === undefined) {
throw new Error('no XAPI associated to ' + uuid)
}
const xapi = yield this._getConnectedXapi(xapiId)
return xapi.getRecordByUuid(type, uuid)
}
}

View File

@@ -47,7 +47,7 @@ export default class Backups {
await fromCallback(execFile, 'pvscan', ['--cache'])
})
let run = ({ xapis, ...rest }) =>
let run = ({ recordToXapi, xapis, ...rest }) =>
new Backup({
...rest,
@@ -56,7 +56,15 @@ export default class Backups {
// pass getAdapter in order to mutualize the adapter resources usage
getAdapter: this.getAdapter.bind(this),
getConnectedXapi: id => this.getXapi(xapis[id]),
getConnectedRecord: Disposable.factory(async function* getConnectedRecord(type, uuid) {
const xapiId = recordToXapi[uuid]
if (xapiId === undefined) {
throw new Error('no XAPI associated to ' + uuid)
}
const xapi = yield this.getXapi(xapis[xapiId])
return xapi.getRecordByUuid(type, uuid)
}),
}).run()
const runningJobs = { __proto__: null }