Skip to content

Commit

Permalink
feat: nodeManager is now startStop
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes authored and emmacasolin committed Jun 14, 2022
1 parent f8b3320 commit faf712d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/nodes/NodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { NodeId, NodeAddress, NodeBucket } from '../nodes/types';
import type { ClaimEncoded } from '../claims/types';
import type { Timer } from '../types';
import Logger from '@matrixai/logger';
import { StartStop } from '@matrixai/async-init/dist/StartStop';
import * as nodesErrors from './errors';
import * as nodesUtils from './utils';
import * as networkUtils from '../network/utils';
Expand All @@ -18,6 +19,8 @@ import * as claimsErrors from '../claims/errors';
import * as sigchainUtils from '../sigchain/utils';
import * as claimsUtils from '../claims/utils';

interface NodeManager extends StartStop {}
@StartStop()
class NodeManager {
protected db: DB;
protected logger: Logger;
Expand Down Expand Up @@ -49,6 +52,18 @@ class NodeManager {
this.nodeGraph = nodeGraph;
}

public async start() {
this.logger.info(`Starting ${this.constructor.name}`);
this.setNodeQueueRunner = this.startSetNodeQueue();
this.logger.info(`Started ${this.constructor.name}`);
}

public async stop() {
this.logger.info(`Stopping ${this.constructor.name}`);
await this.stopSetNodeQueue();
this.logger.info(`Stopped ${this.constructor.name}`);
}

/**
* Determines whether a node in the Polykey network is online.
* @return true if online, false if offline
Expand Down
6 changes: 6 additions & 0 deletions src/nodes/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { ErrorPolykey, sysexits } from '../errors';

class ErrorNodes<T> extends ErrorPolykey<T> {}

class ErrorNodeManagerNotRunning extends ErrorNodes {
static description = 'NodeManager is not running';
exitCode = sysexits.USAGE;
}

class ErrorNodeGraphRunning<T> extends ErrorNodes<T> {
static description = 'NodeGraph is running';
exitCode = sysexits.USAGE;
Expand Down Expand Up @@ -74,6 +79,7 @@ class ErrorNodeConnectionHostWildcard<T> extends ErrorNodes<T> {

export {
ErrorNodes,
ErrorNodeManagerNotRunning,
ErrorNodeGraphRunning,
ErrorNodeGraphNotRunning,
ErrorNodeGraphDestroyed,
Expand Down

0 comments on commit faf712d

Please sign in to comment.