UBERF-5932: Fix account upgrade (#4912)

This commit is contained in:
Andrey Sobolev 2024-03-09 22:14:13 +07:00 committed by GitHub
parent 1ff82a9c15
commit c72300b777
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 14 deletions

View File

@ -79,23 +79,42 @@ async function loadPlugin (id: Plugin): Promise<Resources> {
plugin: id
})
pluginLoader = monitor(status, getLocation(id)()).then(async (plugin) => {
try {
// In case of ts-node, we have a bit different import structure, so let's check for it.
if (typeof plugin.default === 'object') {
// eslint-disable-next-line @typescript-eslint/return-await
return await (plugin as any).default.default()
return await retryLoading(async () => {
try {
// In case of ts-node, we have a bit different import structure, so let's check for it.
if (typeof plugin.default === 'object') {
// eslint-disable-next-line @typescript-eslint/return-await
return await (plugin as any).default.default()
}
return await plugin.default()
} catch (err: any) {
console.error(err)
throw err
}
return await plugin.default()
} catch (err: any) {
console.error(err)
throw err
}
})
})
loading.set(id, pluginLoader)
}
return await pluginLoader
}
async function retryLoading (op: () => Promise<Resources>): Promise<Resources> {
let lastErr: any
for (let i = 0; i < 3; i++) {
try {
return await op()
} catch (err: any) {
if (/Loading chunk [\d]+ failed/.test(err.message)) {
// Do not report on console and try to load again.
// After a short delay
await new Promise((resolve) => setTimeout(resolve, 50))
}
lastErr = err
}
}
throw lastErr
}
const cachedResource = new Map<string, any>()
/**

View File

@ -771,18 +771,17 @@ export async function upgradeWorkspace (
}
const versionStr = versionToString(version)
const currentVersion = await db.collection<Workspace>(WORKSPACE_COLLECTION).findOne({ workspace: ws.workspace })
console.log(
`${forceUpdate ? 'force-' : ''}upgrade from "${
currentVersion?.version !== undefined ? versionToString(currentVersion.version) : ''
ws?.version !== undefined ? versionToString(ws.version) : ''
}" to "${versionStr}"`
)
if (currentVersion?.version !== undefined && !forceUpdate && versionStr === versionToString(currentVersion.version)) {
if (ws?.version !== undefined && !forceUpdate && versionStr === versionToString(ws.version)) {
return versionStr
}
await db.collection(WORKSPACE_COLLECTION).updateOne(
{ workspace: ws.workspace },
{ _id: ws._id },
{
$set: { version }
}