mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +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 elapsedWaitMs = 0
|
||||||
let pollAttempt = 0
|
let pollAttempt = 0
|
||||||
|
|
||||||
for (;;) {
|
while (elapsedWaitMs < MAX_RESTORE_WAIT_MS) {
|
||||||
const restoreCheck = await checkOrInitiateColdRestoreActivity({ key: prep.key })
|
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 (restoreCheck.status === 'ready') {
|
||||||
if (nextCheck.status === 'ready') {
|
const copyResult = await copyOriginalFromArchiveToMainActivity({
|
||||||
|
storageKeyId: prep.storageKeyId,
|
||||||
|
key: prep.key,
|
||||||
|
expectedSize: prep.expectedSize,
|
||||||
|
contentType: prep.contentType,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (copyResult.status === 'copied') {
|
||||||
break
|
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
|
const waitMs = pollAttempt < 10 ? initialPollMs : steadyPollMs
|
||||||
await sleep(waitMs)
|
await sleep(waitMs)
|
||||||
elapsedWaitMs += waitMs
|
elapsedWaitMs += waitMs
|
||||||
pollAttempt++
|
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({
|
await commitRestoreDbStateActivity({
|
||||||
storageKeyId: prep.storageKeyId,
|
storageKeyId: prep.storageKeyId,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user