mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
device os-update: Refactor to use the overall_progress field
Change-type: patch Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
This commit is contained in:
parent
f7d4a37060
commit
3e4f9f9572
@ -1,41 +0,0 @@
|
||||
/*
|
||||
Copyright 2016-2017 Balena
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import * as BalenaDeviceStatus from 'balena-device-status';
|
||||
import { Device } from 'balena-sdk';
|
||||
|
||||
export const getDeviceOsProgress = (device: Device) => {
|
||||
if (!device.is_online) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const status = BalenaDeviceStatus.getStatus(device).key;
|
||||
|
||||
if (
|
||||
status === BalenaDeviceStatus.status.UPDATING &&
|
||||
!!device.download_progress
|
||||
) {
|
||||
return device.download_progress;
|
||||
}
|
||||
if (
|
||||
(status === BalenaDeviceStatus.status.CONFIGURING ||
|
||||
status === BalenaDeviceStatus.status.POST_PROVISIONING) &&
|
||||
device.provisioning_progress
|
||||
) {
|
||||
return device.provisioning_progress;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
@ -279,7 +279,6 @@ export function awaitDevice(uuid: string) {
|
||||
|
||||
export function awaitDeviceOsUpdate(uuid: string, targetOsVersion: string) {
|
||||
const balena = getBalenaSdk();
|
||||
const { getDeviceOsProgress } = require('./device/progress');
|
||||
|
||||
return balena.models.device.getName(uuid).then(deviceName => {
|
||||
const visuals = getVisuals();
|
||||
@ -291,8 +290,8 @@ export function awaitDeviceOsUpdate(uuid: string, targetOsVersion: string) {
|
||||
const poll = (): Bluebird<void> => {
|
||||
return Bluebird.all([
|
||||
balena.models.device.getOsUpdateStatus(uuid),
|
||||
balena.models.device.get(uuid).then(getDeviceOsProgress),
|
||||
]).then(([osUpdateStatus, osUpdateProgress]) => {
|
||||
balena.models.device.get(uuid, { $select: 'overall_progress' }),
|
||||
]).then(([osUpdateStatus, { overall_progress: osUpdateProgress }]) => {
|
||||
if (osUpdateStatus.status === 'done') {
|
||||
console.info(
|
||||
`The device ${deviceName} has been updated to v${targetOsVersion} and will restart shortly!`,
|
||||
|
Loading…
Reference in New Issue
Block a user