mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 21:57:51 +00:00
Add waiting for created droplets and throw error if error on creation
This commit is contained in:
parent
bb011ff1b9
commit
08653aeee2
@ -227,6 +227,31 @@ export default class InstanceInitCmd extends Command {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
responseBody = await res.json()
|
||||
|
||||
const visuals = getVisuals();
|
||||
const spinner = new visuals.Spinner(
|
||||
`Waiting for droplets to be created`,
|
||||
);
|
||||
|
||||
spinner.start();
|
||||
// God tier code incoming
|
||||
await Promise.all(responseBody.links.actions.map(async (action: any) => {
|
||||
let respBody: any
|
||||
do {
|
||||
await new Promise((r) => setTimeout(() => r(null), 2000)) // Sleep for 2 seconds
|
||||
const waitResp = await fetch(action.href, {
|
||||
headers: {
|
||||
authorization: `Bearer ${options.apiKey}`
|
||||
}
|
||||
})
|
||||
respBody = await waitResp.json()
|
||||
if (respBody.action.status === 'errored') {
|
||||
throw new Error('Error creating droplet')
|
||||
}
|
||||
} while (respBody.action.status !== 'completed')
|
||||
}))
|
||||
spinner.stop();
|
||||
|
||||
console.log('Done! The device should appear in your Dashboard in a few minutes!')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user