Improve livepush UX

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-04-30 15:55:58 +01:00
parent 4557cf626f
commit a832f47508
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
3 changed files with 28 additions and 6 deletions

View File

@ -16,6 +16,7 @@ import {
rebuildSingleTask, rebuildSingleTask,
} from './deploy'; } from './deploy';
import { BuildError } from './errors'; import { BuildError } from './errors';
import { getServiceColourFn } from './logs';
// How often do we want to check the device state // How often do we want to check the device state
// engine has settled (delay in ms) // engine has settled (delay in ms)
@ -131,9 +132,11 @@ export class LivepushManager {
); );
} }
const log = (msg: string) => { const msgString = (msg: string) =>
this.logger.logLivepush(`[service ${serviceName}] ${msg}`); `[${getServiceColourFn(serviceName)(serviceName)}] ${msg}`;
}; const log = (msg: string) => this.logger.logLivepush(msgString(msg));
const error = (msg: string) => this.logger.logError(msgString(msg));
const debugLog = (msg: string) => this.logger.logDebug(msgString(msg));
const livepush = await Livepush.init( const livepush = await Livepush.init(
dockerfile, dockerfile,
@ -149,6 +152,16 @@ export class LivepushManager {
livepush.on('commandOutput', output => livepush.on('commandOutput', output =>
log(` ${output.output.data.toString()}`), log(` ${output.output.data.toString()}`),
); );
livepush.on('commandReturn', ({ returnCode, command }) => {
if (returnCode !== 0) {
error(` Command ${command} failed with exit code: ${returnCode}`);
} else {
debugLog(`Command ${command} exited successfully`);
}
});
livepush.on('containerRestart', () => {
log('Restarting service...');
});
// TODO: Memoize this for containers which share a context // TODO: Memoize this for containers which share a context
const monitor = chokidar.watch('.', { const monitor = chokidar.watch('.', {
@ -294,7 +307,16 @@ export class LivepushManager {
this.logger.logLivepush( this.logger.logLivepush(
`Detected changes for container ${fsEvent.serviceName}, updating...`, `Detected changes for container ${fsEvent.serviceName}, updating...`,
); );
await livepush.performLivepush(updates, deletes);
try {
await livepush.performLivepush(updates, deletes);
} catch (e) {
this.logger.logError(
`An error occured whilst trying to perform a livepush: `,
);
this.logger.logError(` ${e.message}`);
this.logger.logDebug(e.stack);
}
} }
private async handleServiceRebuild(serviceName: string): Promise<void> { private async handleServiceRebuild(serviceName: string): Promise<void> {

View File

@ -107,7 +107,7 @@ export function displayLogObject<T extends Log>(
logger.logLogs(toPrint); logger.logLogs(toPrint);
} }
const getServiceColourFn = _.memoize(_getServiceColourFn); export const getServiceColourFn = _.memoize(_getServiceColourFn);
const colorHash = new ColorHash(); const colorHash = new ColorHash();
function _getServiceColourFn(serviceName: string): (msg: string) => string { function _getServiceColourFn(serviceName: string): (msg: string) => string {

View File

@ -144,7 +144,7 @@
"is-root": "^1.0.0", "is-root": "^1.0.0",
"js-yaml": "^3.10.0", "js-yaml": "^3.10.0",
"klaw": "^3.0.0", "klaw": "^3.0.0",
"livepush": "^1.1.3", "livepush": "^1.2.0",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
"mixpanel": "^0.10.1", "mixpanel": "^0.10.1",