Skip to content

Commit

Permalink
add retry in engine commands
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Nov 27, 2019
1 parent 1957fd9 commit 2fadb78
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions cli/sdk/src/engineCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export type GetDMMFOptions = {
cwd?: string
prismaPath?: string
datamodelPath?: string
skipRetry?: boolean
retry?: number
}

export async function getDMMF({
datamodel,
cwd = process.cwd(),
prismaPath,
datamodelPath,
skipRetry,
retry = 4,
}: GetDMMFOptions): Promise<DMMF.Document> {
prismaPath = prismaPath || (await getPrismaPath())
let result
Expand All @@ -63,17 +63,31 @@ export async function getDMMF({

await unlink(tempDataModelPath)

if (result.stdout.includes('Please wait until the') && retry > 0) {
await new Promise(r => setTimeout(r, 5000))
return getDMMF({
datamodel,
cwd,
prismaPath,
datamodelPath,
retry: retry - 1,
})
}

return JSON.parse(result.stdout)
} catch (e) {
// If this unlikely event happens, try it at least once more
if (e.message.includes('Command failed with exit code 26 (ETXTBSY)')) {
await new Promise(resolve => setTimeout(resolve, 100))
if (
e.message.includes('Command failed with exit code 26 (ETXTBSY)') &&
retry > 0
) {
await new Promise(resolve => setTimeout(resolve, 500))
return getDMMF({
datamodel,
cwd,
prismaPath,
datamodelPath,
skipRetry: true,
retry: retry - 1,
})
}
if (e.stderr) {
Expand Down

0 comments on commit 2fadb78

Please sign in to comment.