From ae40e69e99892e4964df45d8531d974aea07ddb4 Mon Sep 17 00:00:00 2001 From: Skillz Date: Thu, 16 Mar 2023 12:47:19 -0500 Subject: [PATCH] fix: use meisters brilliant worker id formula --- packages/gateway/src/manager.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/gateway/src/manager.ts b/packages/gateway/src/manager.ts index 581f57d3a..b993bffa6 100644 --- a/packages/gateway/src/manager.ts +++ b/packages/gateway/src/manager.ts @@ -64,18 +64,10 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate ) }, calculateWorkerId(shardId) { - // Ignore decimal numbers. - let workerId = Math.floor(shardId / gateway.shardsPerWorker) - // If the workerId overflows the maximal allowed workers we by default just use to last worker. - if (workerId >= gateway.totalWorkers) { - // The Id of the last available worker is total -1 - workerId = gateway.totalWorkers - 1 - } - + const workerId = shardId % gateway.shardsPerWorker logger.debug( `[Gateway] Calculating workerId: Shard: ${shardId} -> Worker: ${workerId} -> Per Worker: ${gateway.shardsPerWorker} -> Total: ${gateway.totalWorkers}`, ) - return workerId }, prepareBuckets() { @@ -165,7 +157,7 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate }, events: options.events, requestIdentify: async () => { - await gateway.identify(shardId); + await gateway.identify(shardId) }, shardIsReady: async () => { logger.debug(`[Shard] Shard #${shardId} is ready`)