mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-30 20:28:20 +00:00
fix: better error handling in json migration (#7279)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
5f1535401f
commit
12f93d5c5e
@ -352,7 +352,9 @@ async function processMigrateJsonForDoc (
|
|||||||
|
|
||||||
if (value.startsWith('{')) {
|
if (value.startsWith('{')) {
|
||||||
// For some reason we have documents that are already markups
|
// For some reason we have documents that are already markups
|
||||||
const jsonId = await saveCollabJson(ctx, storageAdapter, workspaceId, collabId, value)
|
const jsonId = await retry(5, async () => {
|
||||||
|
return await saveCollabJson(ctx, storageAdapter, workspaceId, collabId, value)
|
||||||
|
})
|
||||||
update[attributeName] = jsonId
|
update[attributeName] = jsonId
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -371,23 +373,28 @@ async function processMigrateJsonForDoc (
|
|||||||
// If document id has changed, save it with new name to ensure we will be able to load it later
|
// If document id has changed, save it with new name to ensure we will be able to load it later
|
||||||
const ydocId = makeCollabYdocId(collabId)
|
const ydocId = makeCollabYdocId(collabId)
|
||||||
if (ydocId !== currentYdocId) {
|
if (ydocId !== currentYdocId) {
|
||||||
ctx.info('saving collaborative doc with new name', { collabId, ydocId, currentYdocId })
|
await retry(5, async () => {
|
||||||
const buffer = await storageAdapter.read(ctx, workspaceId, currentYdocId)
|
const stat = await storageAdapter.stat(ctx, workspaceId, currentYdocId)
|
||||||
await storageAdapter.put(
|
if (stat !== undefined) {
|
||||||
ctx,
|
const buffer = await storageAdapter.read(ctx, workspaceId, currentYdocId)
|
||||||
workspaceId,
|
await storageAdapter.put(
|
||||||
ydocId,
|
ctx,
|
||||||
Buffer.concat(buffer as any),
|
workspaceId,
|
||||||
'application/ydoc',
|
ydocId,
|
||||||
buffer.length
|
Buffer.concat(buffer as any),
|
||||||
)
|
'application/ydoc',
|
||||||
|
buffer.length
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
const unset = update.$unset ?? {}
|
const error = err instanceof Error ? err.message : String(err)
|
||||||
update.$unset = { ...unset, [attribute.name]: 1 }
|
ctx.warn('failed to process collaborative doc', { workspaceId, collabId, currentYdocId, error })
|
||||||
} catch (err: any) {
|
|
||||||
ctx.warn('failed to process collaborative doc', { workspaceId, collabId, currentYdocId, err: err.message })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unset = update.$unset ?? {}
|
||||||
|
update.$unset = { ...unset, [attribute.name]: 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
return update
|
return update
|
||||||
@ -510,3 +517,19 @@ export const coreOperation: MigrateOperation = {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function retry<T> (retries: number, op: () => Promise<T>): Promise<T> {
|
||||||
|
let error: any
|
||||||
|
while (retries > 0) {
|
||||||
|
retries--
|
||||||
|
try {
|
||||||
|
return await op()
|
||||||
|
} catch (err: any) {
|
||||||
|
error = err
|
||||||
|
if (retries !== 0) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 50))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user