Coding style fixes

This commit is contained in:
wescoeur 2015-11-25 17:13:29 +01:00
parent 8cfc6f0b1d
commit 561b8f4eed

View File

@ -3,6 +3,7 @@ import moment from 'moment'
export const configurationSchema = { export const configurationSchema = {
type: 'object', type: 'object',
description: 'a array of emails (receivers)',
properties: { properties: {
to: { to: {
type: 'array', type: 'array',
@ -65,26 +66,24 @@ class BackupReportsXoPlugin {
nCalls++ nCalls++
let vmName let vm
try { try {
const vm = this._xo.getObject(call.params.id) vm = this._xo.getObject(call.params.id)
vmName = vm.name_label } catch (e) {}
} catch (e) {
vmName = 'Vm name not found'
}
const start = moment(call.start) const start = moment(call.start)
const end = moment(call.end) const end = moment(call.end)
const duration = moment.duration(end - start).humanize() const duration = moment.duration(end - start).humanize()
text.push([`### VM : ${vmName}`, text.push([
`UUID: ${call.params.id}`, `### VM : ${vm ? vm.name_label : 'undefined'}`,
`Status: ${vmStatus}`, ` - UUID: ${vm ? vm.uuid : 'undefined'}`,
`Start time: ${start.toString()}`, ` - Status: ${vmStatus}`,
`End time: ${end.toString()}`, ` - Start time: ${String(start)}`,
`Duration: ${duration}` ` - End time: ${String(end)}`,
].join('\n - ')) ` - Duration: ${duration}`
].join('\n'))
}) })
// No backup calls. // No backup calls.
@ -92,29 +91,27 @@ class BackupReportsXoPlugin {
return return
} }
const globalStatus = nSuccess === nCalls const globalStatus = nSuccess === nCalls ? 'Success' : 'Fail'
? 'Success'
: 'Fail'
const start = moment(status.start) const start = moment(status.start)
const end = moment(status.end) const end = moment(status.end)
const duration = moment.duration(end - start).humanize() const duration = moment.duration(end - start).humanize()
// Global status. // Global status.
text.unshift([`## Global status: ${globalStatus}`, text.unshift([
`Start time: ${start.toString()}`, `## Global status: ${globalStatus}`,
`End time: ${end.toString()}`, ` - Start time: ${String(start)}`,
`Duration: ${duration}`, ` - End time: ${String(end)}`,
`Successful backed up VM number: ${nSuccess}`, ` - Duration: ${duration}`,
`Failed backed up VM: ${nCalls - nSuccess}` ` - Successful backed up VM number: ${nSuccess}`,
].join('\n - ')) ` - Failed backed up VM: ${nCalls - nSuccess}`
].join('\n'))
// TODO : Handle errors when `sendEmail` isn't present. (Plugin dependencies) // TODO : Handle errors when `sendEmail` isn't present. (Plugin dependencies)
this._xo.sendEmail({ await this._xo.sendEmail({
to: this._receivers, to: this._receivers,
subject: 'Backup Reports (XenOrchestra)', subject: 'Backup Reports (XenOrchestra)',
markdown: text.join('\n') markdown: text.join('\n')
}).catch(e => console.error('Unable to send email: ', e)) })
} }
} }