Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
fredriklindberg committed Jan 5, 2024
1 parent 2da9315 commit 0dbeb4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/cluster/cluster-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class ClusterManager {
}

this.initialized = true;
this.ready = false;
this.logger.info(`Clustering mode ${type} initialized`);
}

Expand All @@ -129,10 +130,14 @@ class ClusterManager {
this._bus = <any>undefined;
}

public static async setReady(ready: boolean = true): Promise<boolean> {
public static isMultinode(): boolean {
return this.multiNode;
}

public static async setReady(ready: boolean): Promise<void> {
if (!ready) {
clearInterval(this._heartbeat);
return this.multiNode;
return;
}

const heartbeat = () => {
Expand All @@ -142,7 +147,7 @@ class ClusterManager {
this._heartbeat = setInterval(heartbeat, this._heartbeatInterval);

if (!this.multiNode) {
return this.multiNode;
return;
}

const rapidHeartbeat = setInterval(heartbeat, 2000);
Expand All @@ -155,7 +160,7 @@ class ClusterManager {
setTimeout(resolve, waitTime);
});
clearInterval(rapidHeartbeat);
return this.multiNode;
return;
}

public static attach(callback: EmitCallback): void {
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default async (argv) => {
process.exit(-1);
});

await ClusterManager.setReady();
await ClusterManager.setReady(true);
adminController.setReady();
logger.info("exposrd ready");

Expand All @@ -200,13 +200,13 @@ export default async (argv) => {

let result;
try {
const multiNode = ClusterManager.setReady(false);
ClusterManager.setReady(false);
adminController.setReady(false);

// Drain and block new tunnel connections
await Promise.race([TunnelConnectionManager.stop() , timeout, force]);

if (multiNode) {
if (ClusterManager.isMultinode()) {
logger.info("Waiting for connections to drain...");
await Promise.race([new Promise((resolve) => {
setTimeout(resolve, drainTimeout);
Expand Down

0 comments on commit 0dbeb4c

Please sign in to comment.