UNPKG

@hashgraph/hedera-local

Version:

Developer tooling for running Local Hedera Network (Consensus + Mirror Nodes).

65 lines 3.06 kB
"use strict"; // SPDX-License-Identifier: Apache-2.0 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RecoveryState = void 0; const LoggerService_1 = require("../services/LoggerService"); const ServiceLocator_1 = require("../services/ServiceLocator"); const EventType_1 = require("../types/EventType"); const DockerService_1 = require("../services/DockerService"); const constants_1 = require("../constants"); /** * Represents the recovery state of the Hedera Local Node. * @implements {IState} * @property {LoggerService} logger - The logger service. * @property {IOBserver | undefined} observer - The observer of the state. * @property {string} stateName - The name of the state. * @property {EventType} eventType - The event type that triggered the recovery state. */ class RecoveryState { /** * Creates a new instance of the RecoveryState class. * @param {EventType} eventType - The type of event. */ constructor(eventType) { this.stateName = RecoveryState.name; this.logger = ServiceLocator_1.ServiceLocator.Current.get(LoggerService_1.LoggerService.name); this.dockerService = ServiceLocator_1.ServiceLocator.Current.get(DockerService_1.DockerService.name); this.logger.trace(constants_1.RECOVERY_STATE_INIT_MESSAGE, this.stateName); this.eventType = eventType; } /** * Subscribes an observer to receive updates from the RecoveryState. * @param {IOBserver} observer - The observer to subscribe. */ subscribe(observer) { this.observer = observer; } /** * Starts the recovery state. * @returns {Promise<void>} A promise that resolves when the recovery state has started. */ onStart() { return __awaiter(this, void 0, void 0, function* () { var _a; this.logger.info(constants_1.RECOVERY_STATE_STARTING_MESSAGE, this.stateName); switch (this.eventType) { case EventType_1.EventType.DockerError: yield this.dockerService.tryDockerRecovery(this.stateName); default: (_a = this.observer) === null || _a === void 0 ? void 0 : _a.update(EventType_1.EventType.UnknownError); break; } }); } } exports.RecoveryState = RecoveryState; //# sourceMappingURL=RecoveryState.js.map