Commit efb8690d authored by nanahira's avatar nanahira

add windbot join retry

parent 6d92cdf5
Pipeline #43315 failed with stages
in 2 minutes and 50 seconds
...@@ -78,7 +78,7 @@ export class ClientHandler { ...@@ -78,7 +78,7 @@ export class ClientHandler {
private logger = this.ctx.createLogger('ClientHandler'); private logger = this.ctx.createLogger('ClientHandler');
async handleClient(client: Client): Promise<void> { async handleClient(client: Client) {
client.init(); client.init();
// 将 disconnect$ 映射为 YGOProCtosDisconnect 消息 // 将 disconnect$ 映射为 YGOProCtosDisconnect 消息
...@@ -124,10 +124,11 @@ export class ClientHandler { ...@@ -124,10 +124,11 @@ export class ClientHandler {
), ),
]).pipe(timeout(5000), takeUntil(client.disconnect$)); ]).pipe(timeout(5000), takeUntil(client.disconnect$));
firstValueFrom(handshake$) return firstValueFrom(handshake$)
.then(() => { .then(() => {
this.logger.debug({ client: client.name }, 'Handshake completed'); this.logger.debug({ client: client.name }, 'Handshake completed');
client.established = true; client.established = true;
return true;
}) })
.catch((error) => { .catch((error) => {
this.logger.debug( this.logger.debug(
...@@ -140,6 +141,7 @@ export class ClientHandler { ...@@ -140,6 +141,7 @@ export class ClientHandler {
'Handshake failed, disconnecting client', 'Handshake failed, disconnecting client',
); );
client.disconnect(); client.disconnect();
return false;
}); });
} }
} }
......
...@@ -309,20 +309,52 @@ export class WindBotProvider { ...@@ -309,20 +309,52 @@ export class WindBotProvider {
token: string, token: string,
botName: string, botName: string,
url: URL, url: URL,
) { retryCount = 0,
): Promise<boolean> {
const retryLimit = 3;
const retry = async () => {
// wait 200 ms
await new Promise((resolve) => setTimeout(resolve, 200));
this.logger.warn(
{ roomToken: token, botName, retryCount },
'Retrying windbot join by reverse ws',
);
return this.requestWindbotJoinByReverseWs(
room,
token,
botName,
url,
retryCount + 1,
);
};
try { try {
const sock = await this.createReverseWsConnection(url); const sock = await this.createReverseWsConnection(url);
const client = new ReverseWsClient(this.ctx, sock); const client = new ReverseWsClient(this.ctx, sock);
this.clientHandler.handleClient(client).catch((error) => { const res = await this.clientHandler
.handleClient(client)
.catch((error) => {
this.logger.warn(
{
roomToken: token,
botName,
error: (error as Error).toString(),
},
'Reverse ws windbot client handler failed',
);
});
if (!res) {
this.logger.warn( this.logger.warn(
{ { roomToken: token, botName },
roomToken: token, 'Reverse ws windbot client failed to establish connection',
botName,
error: (error as Error).toString(),
},
'Reverse ws windbot client handler failed',
); );
}); if (retryCount < retryLimit) {
return retry();
}
await room.sendChat('#{add_windbot_failed}', ChatColor.RED);
return false;
}
return true; return true;
} catch (error) { } catch (error) {
...@@ -334,6 +366,9 @@ export class WindBotProvider { ...@@ -334,6 +366,9 @@ export class WindBotProvider {
}, },
'Windbot reverse ws request failed', 'Windbot reverse ws request failed',
); );
if (retryCount < retryLimit) {
return retry();
}
await room.sendChat('#{add_windbot_failed}', ChatColor.RED); await room.sendChat('#{add_windbot_failed}', ChatColor.RED);
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment