mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-24 15:56:40 +00:00
Merge pull request #1243 from balena-io/catch-fetch-error
Add newTargetState event and use it for backup loading
This commit is contained in:
commit
2271071c89
@ -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();
|
||||
|
||||
// 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,
|
||||
await this.getTargetState(),
|
||||
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