feat(xo-server/jobs): backup job support for webhooks (#5360)

Fixes #5205
This commit is contained in:
Mathieu 2020-11-27 10:15:51 +01:00 committed by GitHub
parent a776eaf61a
commit 31b19725b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View File

@ -13,6 +13,7 @@
- [Dashboard/Health] List VMs with missing or outdated guest tools (PR [#5376](https://github.com/vatesfr/xen-orchestra/pull/5376))
- [VIF] Ability for admins to set any allowed IPs, including IPv6 and IPs that are not in an IP pool [#2535](https://github.com/vatesfr/xen-orchestra/issues/2535) [#1872](https://github.com/vatesfr/xen-orchestra/issues/1872) (PR [#5367](https://github.com/vatesfr/xen-orchestra/pull/5367))
- [Proxy] Ability to restore a file from VM backup (PR [#5359](https://github.com/vatesfr/xen-orchestra/pull/5359))
- [Web Hooks] `backupNg.runJob` is now triggered by scheduled runs [#5205](https://github.com/vatesfr/xen-orchestra/issues/5205) (PR [#5360](https://github.com/vatesfr/xen-orchestra/pull/5360))
### Bug fixes
@ -46,4 +47,5 @@
- vhd-lib major
- xo-vmdk-to-vhd major
- xo-server minor
- xo-server-web-hooks minor
- xo-web minor

View File

@ -76,11 +76,15 @@ class XoServerHooks {
load() {
this._xo.on('xo:preCall', this._handlePreHook)
this._xo.on('xo:postCall', this._handlePostHook)
this._xo.on('backup:preCall', this._handlePreHook)
this._xo.on('backup:postCall', this._handlePostHook)
}
unload() {
this._xo.removeListener('xo:preCall', this._handlePreHook)
this._xo.removeListener('xo:postCall', this._handlePostHook)
this._xo.removeListener('backup:preCall', this._handlePreHook)
this._xo.removeListener('backup:postCall', this._handlePostHook)
}
async test({ url }) {

View File

@ -263,6 +263,20 @@ export default class Jobs {
})
const app = this._app
const user = await app.getUser(job.userId)
const data = {
callId: Math.random().toString(36).slice(2),
method: 'backupNg.runJob',
params: {
id: job.id,
schedule: schedule.id,
settings: job.settings,
vms: job.vms,
},
timestamp: Date.now(),
userId: job.userId,
userName: user?.name ?? '(unknown user)',
}
try {
const runningJobs = this._runningJobs
@ -288,6 +302,8 @@ export default class Jobs {
session = app.createUserConnection()
session.set('user_id', job.userId)
type === 'backup' && app.emit('backup:preCall', data)
const status = await executor({
app,
cancelToken: token,
@ -308,6 +324,16 @@ export default class Jobs {
true
)
const now = Date.now()
type === 'backup' &&
app.emit('backup:postCall', {
...data,
duration: now - data.timestamp,
// Result of runJobSequence()
result: true,
timestamp: now,
})
app.emit('job:terminated', runJobId, {
type: job.type,
status,
@ -330,6 +356,14 @@ export default class Jobs {
},
true
)
const now = Date.now()
type === 'backup' &&
app.emit('backup:postCall', {
...data,
duration: now - data.timestamp,
error: serializeError(error),
timestamp: now,
})
app.emit('job:terminated', runJobId, {
type: job.type,
})