fix(xo-server): don't require start for Redis collections (#6872)

Introduced by 9f3b02036

Redis connection is usable right after starting the core, therefore collections can be created
on the `core started` event and does not require for the (much heavier) `start` hook to run.

This change fixes `xo-server-recover-account`.
This commit is contained in:
Julien Fontanet
2023-06-01 10:36:02 +02:00
committed by GitHub
parent b18ebcc38d
commit fba86bf653
9 changed files with 31 additions and 27 deletions

View File

@@ -30,5 +30,6 @@
<!--packages-start-->
- @xen-orchestra/backups patch
- xo-server patch
<!--packages-end-->

View File

@@ -12,7 +12,7 @@ export default class {
constructor(app) {
this._app = app
app.hooks.on('start', () => {
app.hooks.on('core started', () => {
const aclsDb = (this._acls = new Acls({
connection: app._redis,
namespace: 'acl',

View File

@@ -80,7 +80,7 @@ export default class {
return tokensDb.rebuildIndexes()
})
app.hooks.on('start', () => {
app.hooks.on('core started', () => {
// Creates persistent collections.
const tokensDb = (this._tokens = new Tokens({
connection: app._redis,

View File

@@ -14,7 +14,7 @@ export default class {
this._app = app
app.hooks.on('clean', () => this._db.rebuildIndexes())
app.hooks.on('start', () => {
app.hooks.on('core started', () => {
const db = (this._db = new CloudConfigs({
connection: app._redis,
namespace: 'cloudConfig',

View File

@@ -80,15 +80,13 @@ export default class Jobs {
executors.call = executeCall
app.hooks.on('clean', () => this._jobs.rebuildIndexes())
app.hooks.on('start', async () => {
app.hooks.on('core started', () => {
const jobsDb = (this._jobs = new JobsDb({
connection: app._redis,
namespace: 'job',
indexes: ['user_id', 'key'],
}))
this._logger = await app.getLogger('jobs')
app.addConfigManager(
'jobs',
() => jobsDb.get(),
@@ -96,6 +94,9 @@ export default class Jobs {
['users']
)
})
app.hooks.on('start', async () => {
this._logger = await app.getLogger('jobs')
})
// it sends a report for the interrupted backup jobs
app.on('plugins:registered', () =>
asyncMapSettled(this._jobs.get(), job => {

View File

@@ -20,7 +20,7 @@ export default class {
}).addVocabulary(['$multiline', '$type', 'enumNames'])
this._plugins = { __proto__: null }
app.hooks.on('start', () => {
app.hooks.on('core started', () => {
this._pluginsMetadata = new PluginsMetadata({
connection: app._redis,
namespace: 'plugin-metadata',

View File

@@ -70,7 +70,7 @@ export default class Proxy {
})
app.hooks.on('clean', () => this._db.rebuildIndexes())
app.hooks.on('start', () => {
app.hooks.on('core started', () => {
const db = (this._db = new Collection({
connection: app._redis,
indexes: ['address', 'vmUuid'],

View File

@@ -37,7 +37,7 @@ export default class {
this._app = app
app.hooks.on('clean', () => this._remotes.rebuildIndexes())
app.hooks.on('start', async () => {
app.hooks.on('core started', () => {
this._remotes = new Remotes({
connection: app._redis,
namespace: 'remote',
@@ -49,7 +49,8 @@ export default class {
() => this._remotes.get(),
remotes => Promise.all(remotes.map(remote => this._remotes.update(remote)))
)
})
app.hooks.on('start', async () => {
const remotes = await this._remotes.get()
remotes.forEach(remote => {
ignoreErrors.call(this.updateRemote(remote.id, {}))

View File

@@ -56,35 +56,36 @@ export default class XenServers {
})
app.hooks.on('clean', () => this._servers.rebuildIndexes())
app.hooks.on('start', async () => {
const connectServers = async () => {
// Connects to existing servers.
for (const server of await this._servers.get()) {
if (server.enabled) {
this.connectXenServer(server.id).catch(error => {
log.warn('failed to connect to XenServer', {
host: server.host,
error,
})
})
}
}
}
app.hooks.on('core started', () => {
const serversDb = (this._servers = new Servers({
connection: app._redis,
namespace: 'server',
indexes: ['host'],
}))
const connectServers = async () => {
// Connects to existing servers.
for (const server of await serversDb.get()) {
if (server.enabled) {
this.connectXenServer(server.id).catch(error => {
log.warn('failed to connect to XenServer', {
host: server.host,
error,
})
})
}
}
}
app.addConfigManager(
'xenServers',
() => serversDb.get(),
servers => serversDb.update(servers).then(connectServers)
)
})
app.hooks.on('start', async () => {
// Add servers in XenStore
if (!(await serversDb.exists())) {
if (!(await this._servers.exists())) {
const key = 'vm-data/xen-servers'
const xenStoreServers = await XenStore.read(key)
.then(JSON.parse)