Skip to content

Commit

Permalink
fix(xo-web/logs): fix restarting VMs with concurrency issue
Browse files Browse the repository at this point in the history
Fixes #3603
  • Loading branch information
badrAZ committed Nov 5, 2018
1 parent ac2c40c commit cbbb9e7
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/xo-web/src/xo-app/logs/log-alert-header.js
Expand Up @@ -9,6 +9,7 @@ import Icon from 'icon'
import React from 'react'
import ReportBugButton, { CAN_REPORT_BUG } from 'report-bug-button'
import Tooltip from 'tooltip'
import { difference } from 'lodash'
import { get } from '@xen-orchestra/defined'
import { injectState, provideState } from 'reaclette'
import { runBackupNgJob, subscribeBackupNgLogs } from 'xo'
Expand All @@ -27,13 +28,31 @@ export default decorate([
effects: {
restartFailedVms: () => async (
_,
{ log: { jobId: id, scheduleId: schedule, tasks } }
{ log: { jobId: id, scheduleId: schedule, tasks, infos } }
) => {
let vms, successfulVmsIds
const scheduledVms = get(
() => infos.find(({ message }) => message === 'vms').data.vms
)

if (scheduledVms !== undefined) {
successfulVmsIds = []
tasks.forEach(task => {
if (task.status === 'success') {
successfulVmsIds.push(task.data.id)
}
})
vms = difference(scheduledVms, successfulVmsIds)
}

await runBackupNgJob({
id,
schedule,
vms:
tasks && tasks.filter(isFailureTask).map(vmTask => vmTask.data.id),
vms ||
get(() =>
tasks.filter(isFailureTask).map(vmTask => vmTask.data.id)
),
})
},
},
Expand Down

0 comments on commit cbbb9e7

Please sign in to comment.