refactor(@xen-orchestra/backups): use a factory to instantiate backup job
This commit is contained in:
@@ -13,10 +13,10 @@ const { createDebounceResource } = require('@vates/disposable/debounceResource.j
|
||||
const { decorateMethodsWith } = require('@vates/decorate-with')
|
||||
const { deduped } = require('@vates/disposable/deduped.js')
|
||||
const { getHandler } = require('@xen-orchestra/fs')
|
||||
const { instantiateBackupJob } = require('./backupJob.js')
|
||||
const { parseDuration } = require('@vates/parse-duration')
|
||||
const { Xapi } = require('@xen-orchestra/xapi')
|
||||
|
||||
const { Backup } = require('./Backup.js')
|
||||
const { RemoteAdapter } = require('./RemoteAdapter.js')
|
||||
const { Task } = require('./Task.js')
|
||||
|
||||
@@ -48,7 +48,7 @@ class BackupWorker {
|
||||
}
|
||||
|
||||
run() {
|
||||
return new Backup({
|
||||
return instantiateBackupJob({
|
||||
config: this.#config,
|
||||
getAdapter: remoteId => this.getAdapter(this.#remotes[remoteId]),
|
||||
getConnectedRecord: Disposable.factory(async function* getConnectedRecord(type, uuid) {
|
||||
|
||||
20
@xen-orchestra/backups/backupJob.js
Normal file
20
@xen-orchestra/backups/backupJob.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const { Backup } = require('./Backup.js')
|
||||
|
||||
exports.instantiateBackupJob = function instantiateBackupJob({
|
||||
config,
|
||||
getAdapter,
|
||||
getConnectedRecord,
|
||||
job,
|
||||
schedule,
|
||||
}) {
|
||||
switch (job.type) {
|
||||
case 'backup':
|
||||
return new Backup({ config, getAdapter, getConnectedRecord, job, schedule })
|
||||
case 'metadataBackup':
|
||||
return new Backup({ config, getAdapter, getConnectedRecord, job, schedule })
|
||||
default:
|
||||
throw new Error(`No runner for the backup type ${job.type}`)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import Disposable from 'promise-toolbox/Disposable'
|
||||
import fromCallback from 'promise-toolbox/fromCallback'
|
||||
import { asyncMap } from '@xen-orchestra/async-map'
|
||||
import { Backup } from '@xen-orchestra/backups/Backup.js'
|
||||
import { compose } from '@vates/compose'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { decorateMethodsWith } from '@vates/decorate-with'
|
||||
@@ -10,6 +9,7 @@ import { defer } from 'golike-defer'
|
||||
import { DurablePartition } from '@xen-orchestra/backups/DurablePartition.js'
|
||||
import { execFile } from 'child_process'
|
||||
import { formatVmBackups } from '@xen-orchestra/backups/formatVmBackups.js'
|
||||
import { instantiateBackupJob } from '@xen-orchestra/backups/backupJob.js'
|
||||
import { ImportVmBackup } from '@xen-orchestra/backups/ImportVmBackup.js'
|
||||
import { JsonRpcError } from 'json-rpc-protocol'
|
||||
import { Readable } from 'stream'
|
||||
@@ -52,7 +52,7 @@ export default class Backups {
|
||||
const config = app.config.get('backups')
|
||||
if (config.disableWorkers) {
|
||||
const { recordToXapi, remotes, xapis, ...rest } = params
|
||||
return new Backup({
|
||||
return instantiateBackupJob({
|
||||
...rest,
|
||||
|
||||
config,
|
||||
|
||||
@@ -3,13 +3,13 @@ import Disposable from 'promise-toolbox/Disposable'
|
||||
import forOwn from 'lodash/forOwn.js'
|
||||
import groupBy from 'lodash/groupBy.js'
|
||||
import merge from 'lodash/merge.js'
|
||||
import { Backup } from '@xen-orchestra/backups/Backup.js'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { createPredicate } from 'value-matcher'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { formatVmBackups } from '@xen-orchestra/backups/formatVmBackups.js'
|
||||
import { HealthCheckVmBackup } from '@xen-orchestra/backups/HealthCheckVmBackup.js'
|
||||
import { ImportVmBackup } from '@xen-orchestra/backups/ImportVmBackup.js'
|
||||
import { instantiateBackupJob } from '@xen-orchestra/backups/backupJob.js'
|
||||
import { invalidParameters } from 'xo-common/api-errors.js'
|
||||
import { runBackupWorker } from '@xen-orchestra/backups/runBackupWorker.js'
|
||||
import { Task } from '@xen-orchestra/backups/Task.js'
|
||||
@@ -164,7 +164,7 @@ export default class BackupNg {
|
||||
}),
|
||||
},
|
||||
() =>
|
||||
new Backup({
|
||||
instantiateBackupJob({
|
||||
config: backupsConfig,
|
||||
getAdapter: async remoteId =>
|
||||
app.getBackupsRemoteAdapter(await app.getRemoteWithCredentials(remoteId)),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import asyncMapSettled from '@xen-orchestra/async-map/legacy.js'
|
||||
import cloneDeep from 'lodash/cloneDeep.js'
|
||||
import Disposable from 'promise-toolbox/Disposable'
|
||||
import { Backup } from '@xen-orchestra/backups/Backup.js'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { instantiateBackupJob } from '@xen-orchestra/backups/backupJob.js'
|
||||
import { parseMetadataBackupId } from '@xen-orchestra/backups/parseMetadataBackupId.js'
|
||||
import { RestoreMetadataBackup } from '@xen-orchestra/backups/RestoreMetadataBackup.js'
|
||||
import { Task } from '@xen-orchestra/backups/Task.js'
|
||||
@@ -129,7 +129,7 @@ export default class metadataBackup {
|
||||
}),
|
||||
},
|
||||
() =>
|
||||
new Backup({
|
||||
instantiateBackupJob({
|
||||
config: this._app.config.get('backups'),
|
||||
getAdapter: async remoteId => app.getBackupsRemoteAdapter(await app.getRemoteWithCredentials(remoteId)),
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Backup } from '@xen-orchestra/backups/Backup.js'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { defer as deferrable } from 'golike-defer'
|
||||
import { fromEvent } from 'promise-toolbox'
|
||||
import { instantiateBackupJob } from '@xen-orchestra/backups/backupJob.js'
|
||||
import { Task } from '@xen-orchestra/mixins/Tasks.mjs'
|
||||
import { v4 as generateUuid } from 'uuid'
|
||||
import { VDI_FORMAT_VHD } from '@xen-orchestra/xapi'
|
||||
@@ -41,7 +41,7 @@ export default class MigrateVm {
|
||||
const schedule = { id: 'one-time' }
|
||||
|
||||
// for now we only support this from the main OA, no proxy
|
||||
return new Backup({
|
||||
return instantiateBackupJob({
|
||||
config,
|
||||
job,
|
||||
schedule,
|
||||
|
||||
Reference in New Issue
Block a user