mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-21 22:47:49 +00:00
Merge pull request #1190 from balena-io/1189-delay-sending-logs
bug: Delay sending logs until the device is provisioned
This commit is contained in:
commit
468f7c3d66
@ -8,6 +8,8 @@ import { PinejsClientRequest, StatusError } from 'pinejs-client-request';
|
||||
import * as deviceRegister from 'resin-register-device';
|
||||
import * as url from 'url';
|
||||
|
||||
import * as globalEventBus from './event-bus';
|
||||
|
||||
import Config, { ConfigType } from './config';
|
||||
import Database from './db';
|
||||
import { EventTracker } from './event-tracker';
|
||||
@ -929,7 +931,9 @@ export class APIBinder {
|
||||
]);
|
||||
|
||||
if (!conf.provisioned || conf.apiKey != null || conf.pinDevice != null) {
|
||||
return this.provisionOrRetry(conf.bootstrapRetryDelay as number);
|
||||
await this.provisionOrRetry(conf.bootstrapRetryDelay);
|
||||
globalEventBus.getInstance().emit('deviceProvisioned');
|
||||
return;
|
||||
}
|
||||
|
||||
return conf;
|
||||
|
17
src/event-bus.ts
Normal file
17
src/event-bus.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import * as _ from 'lodash';
|
||||
import StrictEventEmitter from 'strict-event-emitter-types';
|
||||
|
||||
export interface GlobalEvents {
|
||||
deviceProvisioned: void;
|
||||
}
|
||||
|
||||
type GlobalEventEmitter = StrictEventEmitter<EventEmitter, GlobalEvents>;
|
||||
|
||||
export class GlobalEventBus extends (EventEmitter as new () => GlobalEventEmitter) {
|
||||
public constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export const getInstance = _.once(() => new GlobalEventBus());
|
@ -1,7 +1,7 @@
|
||||
import * as Bluebird from 'bluebird';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import Config, { ConfigChangeMap, ConfigKey, ConfigType } from './config';
|
||||
import Config, { ConfigType } from './config';
|
||||
import DB from './db';
|
||||
import { EventTracker } from './event-tracker';
|
||||
import Docker from './lib/docker-utils';
|
||||
@ -16,6 +16,7 @@ import {
|
||||
} from './logging';
|
||||
import LogMonitor from './logging/monitor';
|
||||
|
||||
import * as globalEventBus from './event-bus';
|
||||
import log from './lib/supervisor-console';
|
||||
|
||||
interface LoggerSetupOptions {
|
||||
@ -72,17 +73,7 @@ export class Logger {
|
||||
|
||||
// Only setup a config listener if we have to
|
||||
if (!this.balenaBackend.isIntialised()) {
|
||||
const handler = async (values: ConfigChangeMap<ConfigKey>) => {
|
||||
if (
|
||||
'uuid' in values ||
|
||||
'apiEndpoint' in values ||
|
||||
'deviceApiKey' in values
|
||||
) {
|
||||
// If any of the values we're interested in have
|
||||
// changed, retrieve all of the values, check that
|
||||
// they're all set, and provide them to the
|
||||
// balenaBackend
|
||||
|
||||
globalEventBus.getInstance().once('deviceProvisioned', async () => {
|
||||
const conf = await config.getMany([
|
||||
'uuid',
|
||||
'apiEndpoint',
|
||||
@ -101,11 +92,8 @@ export class Logger {
|
||||
conf.uuid!,
|
||||
conf.deviceApiKey,
|
||||
);
|
||||
config.removeListener('change', handler);
|
||||
}
|
||||
}
|
||||
};
|
||||
config.on('change', handler);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,9 +87,6 @@ export class Supervisor {
|
||||
log.debug('Starting event tracker');
|
||||
await this.eventTracker.init(conf);
|
||||
|
||||
log.debug('Starting api binder');
|
||||
await this.apiBinder.initClient();
|
||||
|
||||
log.debug('Starting logging infrastructure');
|
||||
this.logger.init({
|
||||
enableLogs: conf.loggingEnabled,
|
||||
@ -97,6 +94,9 @@ export class Supervisor {
|
||||
...conf,
|
||||
});
|
||||
|
||||
log.debug('Starting api binder');
|
||||
await this.apiBinder.initClient();
|
||||
|
||||
this.logger.logSystemMessage('Supervisor starting', {}, 'Supervisor start');
|
||||
if (conf.legacyAppsPresent && this.apiBinder.balenaApi != null) {
|
||||
log.info('Legacy app detected, running migration');
|
||||
|
Loading…
Reference in New Issue
Block a user