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:
Thodoris Greasidis 2020-04-23 19:34:00 +03:00 committed by GitHub
commit e9f8cadb73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 44 deletions

View File

@ -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;
};

View File

@ -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!`,