feat(xo-server/backupNg.getLogs): extract a subset of logs (#3914)
Related to xoa-support#1024
This commit is contained in:
parent
eb3760ee4a
commit
12bbdba82c
@ -1,5 +1,4 @@
|
|||||||
import { basename } from 'path'
|
import { basename } from 'path'
|
||||||
import { isEmpty, pickBy } from 'lodash'
|
|
||||||
|
|
||||||
import { safeDateFormat } from '../utils'
|
import { safeDateFormat } from '../utils'
|
||||||
|
|
||||||
@ -151,13 +150,24 @@ runJob.params = {
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
export async function getAllLogs(filter) {
|
export function getAllLogs() {
|
||||||
const logs = await this.getBackupNgLogs()
|
return this.getBackupNgLogs()
|
||||||
return isEmpty(filter) ? logs : pickBy(logs, filter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllLogs.permission = 'admin'
|
getAllLogs.permission = 'admin'
|
||||||
|
|
||||||
|
export function getLogs({ after, before, limit, ...filter }) {
|
||||||
|
return this.getBackupNgLogsSorted({ after, before, limit, filter })
|
||||||
|
}
|
||||||
|
|
||||||
|
getLogs.permission = 'admin'
|
||||||
|
|
||||||
|
getLogs.params = {
|
||||||
|
after: { type: ['number', 'string'], optional: true },
|
||||||
|
before: { type: ['number', 'string'], optional: true },
|
||||||
|
limit: { type: 'number', optional: true },
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
export function deleteVmBackup({ id }) {
|
export function deleteVmBackup({ id }) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { forEach } from 'lodash'
|
import ms from 'ms'
|
||||||
|
import { forEach, isEmpty, iteratee, sortedIndexBy } from 'lodash'
|
||||||
import { noSuchObject } from 'xo-common/api-errors'
|
import { noSuchObject } from 'xo-common/api-errors'
|
||||||
|
|
||||||
const isSkippedError = error =>
|
const isSkippedError = error =>
|
||||||
@ -32,6 +33,10 @@ const computeStatusAndSortTasks = (status, tasks) => {
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPropertyValue(key) {
|
||||||
|
return this[key]
|
||||||
|
}
|
||||||
|
|
||||||
const taskTimeComparator = ({ start: s1, end: e1 }, { start: s2, end: e2 }) => {
|
const taskTimeComparator = ({ start: s1, end: e1 }, { start: s2, end: e2 }) => {
|
||||||
if (e1 !== undefined) {
|
if (e1 !== undefined) {
|
||||||
if (e2 !== undefined) {
|
if (e2 !== undefined) {
|
||||||
@ -170,4 +175,48 @@ export default {
|
|||||||
|
|
||||||
return runId === undefined ? consolidated : consolidated[runId]
|
return runId === undefined ? consolidated : consolidated[runId]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getBackupNgLogsSorted({ after, before, filter, limit }) {
|
||||||
|
let logs = await this.getBackupNgLogs()
|
||||||
|
|
||||||
|
// convert to array
|
||||||
|
logs = Object.keys(logs).map(getPropertyValue, logs)
|
||||||
|
|
||||||
|
if (!isEmpty(filter)) {
|
||||||
|
logs = logs.filter(iteratee(filter))
|
||||||
|
}
|
||||||
|
|
||||||
|
logs.sort((a, b) => a.start - b.start)
|
||||||
|
|
||||||
|
// only extract the range we are interested in
|
||||||
|
const i =
|
||||||
|
after === undefined
|
||||||
|
? 0
|
||||||
|
: sortedIndexBy(
|
||||||
|
logs,
|
||||||
|
{
|
||||||
|
start: typeof after === 'number' ? after : Date.now() - ms(after),
|
||||||
|
},
|
||||||
|
'start'
|
||||||
|
)
|
||||||
|
let j =
|
||||||
|
before === undefined
|
||||||
|
? logs.length
|
||||||
|
: sortedIndexBy(
|
||||||
|
logs,
|
||||||
|
{
|
||||||
|
start:
|
||||||
|
typeof before === 'number' ? before : Date.now() - ms(before),
|
||||||
|
},
|
||||||
|
'start'
|
||||||
|
)
|
||||||
|
|
||||||
|
limit += i
|
||||||
|
if (limit < j) {
|
||||||
|
j = limit
|
||||||
|
}
|
||||||
|
logs = logs.slice(i, j)
|
||||||
|
|
||||||
|
return logs
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user