Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-5932: Fix account upgrade #4912

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions packages/platform/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>()

/**
Expand Down
7 changes: 3 additions & 4 deletions server/account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down