mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
UBERF-5932: Fix account upgrade (#4912)
This commit is contained in:
parent
1ff82a9c15
commit
c72300b777
@ -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>()
|
||||
|
||||
/**
|
||||
|
@ -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 }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user