feat(xo-server/jobs): backup job support for webhooks (#5360)
Fixes #5205
This commit is contained in:
parent
a776eaf61a
commit
31b19725b7
@ -13,6 +13,7 @@
|
|||||||
- [Dashboard/Health] List VMs with missing or outdated guest tools (PR [#5376](https://github.com/vatesfr/xen-orchestra/pull/5376))
|
- [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))
|
- [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))
|
- [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
|
### Bug fixes
|
||||||
|
|
||||||
@ -46,4 +47,5 @@
|
|||||||
- vhd-lib major
|
- vhd-lib major
|
||||||
- xo-vmdk-to-vhd major
|
- xo-vmdk-to-vhd major
|
||||||
- xo-server minor
|
- xo-server minor
|
||||||
|
- xo-server-web-hooks minor
|
||||||
- xo-web minor
|
- xo-web minor
|
||||||
|
@ -76,11 +76,15 @@ class XoServerHooks {
|
|||||||
load() {
|
load() {
|
||||||
this._xo.on('xo:preCall', this._handlePreHook)
|
this._xo.on('xo:preCall', this._handlePreHook)
|
||||||
this._xo.on('xo:postCall', this._handlePostHook)
|
this._xo.on('xo:postCall', this._handlePostHook)
|
||||||
|
this._xo.on('backup:preCall', this._handlePreHook)
|
||||||
|
this._xo.on('backup:postCall', this._handlePostHook)
|
||||||
}
|
}
|
||||||
|
|
||||||
unload() {
|
unload() {
|
||||||
this._xo.removeListener('xo:preCall', this._handlePreHook)
|
this._xo.removeListener('xo:preCall', this._handlePreHook)
|
||||||
this._xo.removeListener('xo:postCall', this._handlePostHook)
|
this._xo.removeListener('xo:postCall', this._handlePostHook)
|
||||||
|
this._xo.removeListener('backup:preCall', this._handlePreHook)
|
||||||
|
this._xo.removeListener('backup:postCall', this._handlePostHook)
|
||||||
}
|
}
|
||||||
|
|
||||||
async test({ url }) {
|
async test({ url }) {
|
||||||
|
@ -263,6 +263,20 @@ export default class Jobs {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const app = this._app
|
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 {
|
try {
|
||||||
const runningJobs = this._runningJobs
|
const runningJobs = this._runningJobs
|
||||||
|
|
||||||
@ -288,6 +302,8 @@ export default class Jobs {
|
|||||||
session = app.createUserConnection()
|
session = app.createUserConnection()
|
||||||
session.set('user_id', job.userId)
|
session.set('user_id', job.userId)
|
||||||
|
|
||||||
|
type === 'backup' && app.emit('backup:preCall', data)
|
||||||
|
|
||||||
const status = await executor({
|
const status = await executor({
|
||||||
app,
|
app,
|
||||||
cancelToken: token,
|
cancelToken: token,
|
||||||
@ -308,6 +324,16 @@ export default class Jobs {
|
|||||||
true
|
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, {
|
app.emit('job:terminated', runJobId, {
|
||||||
type: job.type,
|
type: job.type,
|
||||||
status,
|
status,
|
||||||
@ -330,6 +356,14 @@ export default class Jobs {
|
|||||||
},
|
},
|
||||||
true
|
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, {
|
app.emit('job:terminated', runJobId, {
|
||||||
type: job.type,
|
type: job.type,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user