feat(xo-server/remotes): sync on use (#3320)

Fixes #2852
This commit is contained in:
Julien Fontanet 2018-08-16 14:39:24 +02:00 committed by GitHub
parent 355cddc044
commit 942ddfa742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -13,6 +13,7 @@
- [Backup NG form] Fix schedule's name overridden with undefined if it's not been edited [#3286](https://github.com/vatesfr/xen-orchestra/issues/3286) (PR [#3288](https://github.com/vatesfr/xen-orchestra/pull/3288)) - [Backup NG form] Fix schedule's name overridden with undefined if it's not been edited [#3286](https://github.com/vatesfr/xen-orchestra/issues/3286) (PR [#3288](https://github.com/vatesfr/xen-orchestra/pull/3288))
- [Remotes] Don't change `enabled` state on errors (PR [#3318](https://github.com/vatesfr/xen-orchestra/pull/3318)) - [Remotes] Don't change `enabled` state on errors (PR [#3318](https://github.com/vatesfr/xen-orchestra/pull/3318))
- [Remotes] Auto-reconnect on use if necessary [#2852](https://github.com/vatesfr/xen-orchestra/issues/2852) (PR [#3320](https://github.com/vatesfr/xen-orchestra/pull/3320))
### Released packages ### Released packages

View File

@ -59,6 +59,15 @@ export default class {
if (handler === undefined) { if (handler === undefined) {
handler = handlers[id] = getHandler(remote) handler = handlers[id] = getHandler(remote)
} }
try {
await handler.sync()
ignoreErrors.call(this._updateRemote(id, { error: '' }))
} catch (error) {
ignoreErrors.call(this._updateRemote(id, { error: error.message }))
throw error
}
return handler return handler
} }
@ -89,20 +98,15 @@ export default class {
return /* await */ this.updateRemote(remote.get('id'), { enabled: true }) return /* await */ this.updateRemote(remote.get('id'), { enabled: true })
} }
async updateRemote (id, { name, url, enabled }) { updateRemote (id, { name, url, enabled }) {
const remote = await this._updateRemote(id, { name, url, enabled }) const handlers = this._handlers
const handler = handlers[id]
// force refreshing the handler if (handler !== undefined) {
delete this._handlers[id] delete this._handlers[id]
const handler = await this.getRemoteHandler(remote, true) ignoreErrors.call(handler.forget())
let error = ''
try {
await handler.sync()
} catch (error_) {
error = error_.message
} }
return this._updateRemote(id, { error })
return this._updateRemote(id, { name, url, enabled })
} }
@synchronized() @synchronized()