mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 02:09:56 +00:00
refactor(transcode): simplify restore asset workflow to single while loop
This commit is contained in:
@@ -48,50 +48,35 @@ export async function restoreAssetWorkflow(task: WorkflowTask): Promise<void> {
|
||||
let elapsedWaitMs = 0
|
||||
let pollAttempt = 0
|
||||
|
||||
for (;;) {
|
||||
while (elapsedWaitMs < MAX_RESTORE_WAIT_MS) {
|
||||
const restoreCheck = await checkOrInitiateColdRestoreActivity({ key: prep.key })
|
||||
while (restoreCheck.status === 'restoring') {
|
||||
if (elapsedWaitMs >= MAX_RESTORE_WAIT_MS) {
|
||||
throw ApplicationFailure.create({
|
||||
message: `Cold storage restore timed out after 48 hours for key: ${prep.key}`,
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
const waitMs = pollAttempt < 10 ? initialPollMs : steadyPollMs
|
||||
await sleep(waitMs)
|
||||
elapsedWaitMs += waitMs
|
||||
pollAttempt++
|
||||
|
||||
const nextCheck = await checkOrInitiateColdRestoreActivity({ key: prep.key })
|
||||
if (nextCheck.status === 'ready') {
|
||||
if (restoreCheck.status === 'ready') {
|
||||
const copyResult = await copyOriginalFromArchiveToMainActivity({
|
||||
storageKeyId: prep.storageKeyId,
|
||||
key: prep.key,
|
||||
expectedSize: prep.expectedSize,
|
||||
contentType: prep.contentType,
|
||||
})
|
||||
|
||||
if (copyResult.status === 'copied') {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const copyResult = await copyOriginalFromArchiveToMainActivity({
|
||||
storageKeyId: prep.storageKeyId,
|
||||
key: prep.key,
|
||||
expectedSize: prep.expectedSize,
|
||||
contentType: prep.contentType,
|
||||
})
|
||||
|
||||
if (copyResult.status === 'copied') {
|
||||
break
|
||||
}
|
||||
|
||||
// Reactive fallback: copy encountered InvalidObjectState and initiated RestoreObject
|
||||
if (elapsedWaitMs >= MAX_RESTORE_WAIT_MS) {
|
||||
throw ApplicationFailure.create({
|
||||
message: `Cold storage restore timed out after 48 hours for key: ${prep.key}`,
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
const waitMs = pollAttempt < 10 ? initialPollMs : steadyPollMs
|
||||
await sleep(waitMs)
|
||||
elapsedWaitMs += waitMs
|
||||
pollAttempt++
|
||||
}
|
||||
|
||||
if (elapsedWaitMs >= MAX_RESTORE_WAIT_MS) {
|
||||
throw ApplicationFailure.create({
|
||||
message: `Cold storage restore timed out after 48 hours for key: ${prep.key}`,
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
await commitRestoreDbStateActivity({
|
||||
storageKeyId: prep.storageKeyId,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user