mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-31 08:25:36 +00:00
Merge pull request #1744 from balena-io/os-update-overall-progress
device os-update: Refactor to use the overall_progress field
This commit is contained in:
commit
e9f8cadb73
@ -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) {
|
export function awaitDeviceOsUpdate(uuid: string, targetOsVersion: string) {
|
||||||
const balena = getBalenaSdk();
|
const balena = getBalenaSdk();
|
||||||
const { getDeviceOsProgress } = require('./device/progress');
|
|
||||||
|
|
||||||
return balena.models.device.getName(uuid).then(deviceName => {
|
return balena.models.device.getName(uuid).then(deviceName => {
|
||||||
const visuals = getVisuals();
|
const visuals = getVisuals();
|
||||||
@ -291,8 +290,8 @@ export function awaitDeviceOsUpdate(uuid: string, targetOsVersion: string) {
|
|||||||
const poll = (): Bluebird<void> => {
|
const poll = (): Bluebird<void> => {
|
||||||
return Bluebird.all([
|
return Bluebird.all([
|
||||||
balena.models.device.getOsUpdateStatus(uuid),
|
balena.models.device.getOsUpdateStatus(uuid),
|
||||||
balena.models.device.get(uuid).then(getDeviceOsProgress),
|
balena.models.device.get(uuid, { $select: 'overall_progress' }),
|
||||||
]).then(([osUpdateStatus, osUpdateProgress]) => {
|
]).then(([osUpdateStatus, { overall_progress: osUpdateProgress }]) => {
|
||||||
if (osUpdateStatus.status === 'done') {
|
if (osUpdateStatus.status === 'done') {
|
||||||
console.info(
|
console.info(
|
||||||
`The device ${deviceName} has been updated to v${targetOsVersion} and will restart shortly!`,
|
`The device ${deviceName} has been updated to v${targetOsVersion} and will restart shortly!`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user