mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 05:37:53 +00:00
Add newTargetState event and use it for backup loading
Change-type: patch Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
75203d0425
commit
0a429f60a5
@ -8,8 +8,6 @@ import { PinejsClientRequest, StatusError } from 'pinejs-client-request';
|
||||
import * as url from 'url';
|
||||
import * as deviceRegister from './lib/register-device';
|
||||
|
||||
import * as globalEventBus from './event-bus';
|
||||
|
||||
import Config, { ConfigType } from './config';
|
||||
import Database from './db';
|
||||
import { EventTracker } from './event-tracker';
|
||||
@ -30,6 +28,7 @@ import { DeviceStatus, TargetState } from './types/state';
|
||||
import log from './lib/supervisor-console';
|
||||
|
||||
import DeviceState from './device-state';
|
||||
import * as globalEventBus from './event-bus';
|
||||
import Logger from './logger';
|
||||
|
||||
// The exponential backoff starts at 15s
|
||||
@ -207,11 +206,16 @@ export class APIBinder {
|
||||
log.debug('Starting current state report');
|
||||
await this.startCurrentStateReport();
|
||||
|
||||
await loadBackupFromMigration(
|
||||
this.deviceState,
|
||||
await this.getTargetState(),
|
||||
bootstrapRetryDelay,
|
||||
);
|
||||
// When we've provisioned, try to load the backup. We
|
||||
// must wait for the provisioning because we need a
|
||||
// target state on which to apply the backup
|
||||
globalEventBus.getInstance().once('targetStateChanged', async state => {
|
||||
await loadBackupFromMigration(
|
||||
this.deviceState,
|
||||
state,
|
||||
bootstrapRetryDelay,
|
||||
);
|
||||
});
|
||||
|
||||
this.readyForUpdates = true;
|
||||
log.debug('Starting target state poll');
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
CompositionStepAction,
|
||||
} from './compose/composition-steps';
|
||||
import { loadTargetFromFile } from './device-state/preload';
|
||||
import * as globalEventBus from './event-bus';
|
||||
import * as hostConfig from './host-config';
|
||||
import constants = require('./lib/constants');
|
||||
import { InternalInconsistencyError, UpdatesLockedError } from './lib/errors';
|
||||
@ -447,6 +448,9 @@ export class DeviceState extends (EventEmitter as new () => DeviceStateEventEmit
|
||||
this.failedUpdates = 0;
|
||||
|
||||
validateState(target);
|
||||
|
||||
globalEventBus.getInstance().emit('targetStateChanged', target);
|
||||
|
||||
const apiEndpoint = await this.config.get('apiEndpoint');
|
||||
|
||||
await this.usingWriteLockTarget(async () => {
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import * as _ from 'lodash';
|
||||
import StrictEventEmitter from 'strict-event-emitter-types';
|
||||
import { TargetState } from './types/state';
|
||||
|
||||
export interface GlobalEvents {
|
||||
deviceProvisioned: void;
|
||||
targetStateChanged: TargetState;
|
||||
}
|
||||
|
||||
type GlobalEventEmitter = StrictEventEmitter<EventEmitter, GlobalEvents>;
|
||||
|
Loading…
Reference in New Issue
Block a user