diff --git a/src/commands/device/os-update.ts b/src/commands/device/os-update.ts index 580d2eef..47aa5fdf 100644 --- a/src/commands/device/os-update.ts +++ b/src/commands/device/os-update.ts @@ -146,7 +146,18 @@ export default class DeviceOsUpdateCmd extends Command { 'Host OS updates require a device restart when they complete. Are you sure you want to proceed?', ); - await sdk.models.device.startOsUpdate(uuid, targetOsVersion); - await patterns.awaitDeviceOsUpdate(uuid, targetOsVersion); + await sdk.models.device + .startOsUpdate(uuid, targetOsVersion, { + runDetached: true, + }) + .then(() => { + console.log( + `The balena OS update has started. You can keep track of the progress via the dashboard.\n` + + `To open the dashboard page related to a device via the CLI, you can use \`balena device UUID --view\``, + ); + }) + .catch((error) => { + console.error(`Failed to start OS update for device ${uuid}:`, error); + }); } } diff --git a/src/utils/patterns.ts b/src/utils/patterns.ts index 1ea2cafd..b13ba8fd 100644 --- a/src/utils/patterns.ts +++ b/src/utils/patterns.ts @@ -30,9 +30,8 @@ import { ExpectedError, NotAvailableInOfflineModeError, } from '../errors'; -import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy'; +import { getBalenaSdk, stripIndent, getCliForm } from './lazy'; import validation = require('./validation'); -import { delay } from './helpers'; export function authenticate(options: object): Promise { const balena = getBalenaSdk(); @@ -286,51 +285,6 @@ export async function getAndSelectOrganization() { } } -export async function awaitDeviceOsUpdate( - uuid: string, - targetOsVersion: string, -) { - const balena = getBalenaSdk(); - - const deviceName = await balena.models.device.getName(uuid); - const visuals = getVisuals(); - const progressBar = new visuals.Progress( - `Updating the OS of ${deviceName} to v${targetOsVersion}`, - ); - progressBar.update({ percentage: 0 }); - - const poll = async (): Promise => { - const [osUpdateStatus, { overall_progress: osUpdateProgress }] = - await Promise.all([ - balena.models.device.getOsUpdateStatus(uuid), - balena.models.device.get(uuid, { $select: 'overall_progress' }), - ]); - if (osUpdateStatus.status === 'done') { - console.info( - `The device ${deviceName} has been updated to v${targetOsVersion} and will restart shortly!`, - ); - return; - } - - if (osUpdateStatus.error) { - throw new ExpectedError( - `Failed to complete Host OS update on device ${deviceName}\n${osUpdateStatus.error}`, - ); - } - - if (osUpdateProgress !== null) { - // Avoid resetting to 0% at end of process when device goes disconnected. - progressBar.update({ percentage: osUpdateProgress }); - } - - await delay(3000); - await poll(); - }; - - await poll(); - return uuid; -} - /* * Given fleetOrDevice, which may be * - a fleet name