From 46e94921ce602c1371241cb46330ad4cb06f4353 Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Thu, 13 Aug 2026 01:56:38 +0100 Subject: [PATCH] #388(@nikita-petko): RSISRIOFAS #!components: grid-bot-recovery Update build.yml: ~ Add lib/* Update .vscode: ~ Add taks and launch configurations for grid-bot-recovery Update grid-bot component: ~ Add gRPC service endpoint. Update grid-bot-recovery: ~ Move shard count to a once flag, to run initialization once on startup. Please Note: Only interactions will actually respond here for some reason. --- .github/workflows/build.yml | 1 + .vscode/launch.json | 34 ++++++++++++++++++++++++- .vscode/tasks.json | 16 +++++++++++- services/grid-bot/.component.yaml | 10 ++++++++ services/recovery/src/Events/OnReady.cs | 13 +++------- 5 files changed, 63 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a07fdbd0..6d161c9f 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ name: Build on: push: paths: + - "lib/**" - "services/**" - ".github/workflows/build.yml" diff --git a/.vscode/launch.json b/.vscode/launch.json index a8492748..7397b047 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "name": "Grid.Bot", "type": "coreclr", "request": "launch", - "preLaunchTask": "build", + "preLaunchTask": "build: grid-bot", "program": "${workspaceFolder}/services/grid-bot/src/bin/Debug/net8.0/Grid.Bot.dll", "cwd": "${workspaceFolder}/services/grid-bot/src/", "console": "internalConsole", @@ -31,6 +31,38 @@ }, "requireExactSource": false, "envFile": "${workspaceFolder}/.env" + }, + + { + "name": "Grid.Bot.Recovery", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build: grid-bot-recovery", + "program": "${workspaceFolder}/services/recovery/src/bin/Debug/net8.0/Grid.Bot.Recovery.dll", + "cwd": "${workspaceFolder}/services/recovery/src/", + "console": "internalConsole", + "stopAtEntry": false, + "justMyCode": true, + "logging": { + "moduleLoad": false + }, + "requireExactSource": false, + "envFile": "${workspaceFolder}/.env" + }, + { + "name": "Grid.Bot.Recovery (No build)", + "type": "coreclr", + "request": "launch", + "program": "${workspaceFolder}/services/recovery/src/bin/Debug/net8.0/Grid.Bot.Recovery.dll", + "cwd": "${workspaceFolder}/services/recovery/src/", + "console": "internalConsole", + "stopAtEntry": false, + "justMyCode": true, + "logging": { + "moduleLoad": false + }, + "requireExactSource": false, + "envFile": "${workspaceFolder}/.env" } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0ff88f10..c739bb39 100755 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,7 +2,7 @@ "version": "2.0.0", "tasks": [ { - "label": "build", + "label": "build: grid-bot", "command": "dotnet", "type": "process", "args": [ @@ -14,6 +14,20 @@ "/p:Platform=AnyCPU", ], "problemMatcher": "$msCompile" + }, + { + "label": "build: grid-bot-recovery", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/services/recovery/src/Grid.Bot.Recovery.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary", + "/p:Configuration=Debug", + "/p:Platform=AnyCPU", + ], + "problemMatcher": "$msCompile" } ] } \ No newline at end of file diff --git a/services/grid-bot/.component.yaml b/services/grid-bot/.component.yaml index dcc4b714..ffdd67a8 100755 --- a/services/grid-bot/.component.yaml +++ b/services/grid-bot/.component.yaml @@ -59,6 +59,16 @@ deployment: - "traefik.http.routers.${{ env.NOMAD_ENVIRONMENT }}-grid-bot-web.rule=(Host(`clientsettingscdn.sitetest4.robloxlabs.com`) || Host(`versioncompatibility.api.sitetest4.robloxlabs.com`) || Host(`avatar.sitetest4.robloxlabs.com`))" - "traefik.http.routers.${{ env.NOMAD_ENVIRONMENT }}-grid-bot-web.entrypoints=http,https" + - name: ${{ env.NOMAD_ENVIRONMENT }}-grid-bot-grpc + port: grpc + tags: + - ${{ env.NOMAD_ENVIRONMENT }} + + - "traefik.enable=true" + - "traefik.http.routers.${{ env.NOMAD_ENVIRONMENT }}-grid-bot-grpc.rule=Host(`grid-bot-grpc.wck02.vmminfra.dev`)" + - "traefik.http.routers.${{ env.NOMAD_ENVIRONMENT }}-grid-bot-grpc.entrypoints=https" + - "traefik.http.services.${{ env.NOMAD_ENVIRONMENT }}-grid-bot-grpc.loadbalancer.server.scheme=h2c" + volumes: - '/var/run/docker.sock:/var/run/docker.sock' - '/tmp/.X11-unix:/tmp/.X11-unix' diff --git a/services/recovery/src/Events/OnReady.cs b/services/recovery/src/Events/OnReady.cs index 37d3dac9..750d1bbf 100755 --- a/services/recovery/src/Events/OnReady.cs +++ b/services/recovery/src/Events/OnReady.cs @@ -36,7 +36,7 @@ public class OnShardReady( OnInteraction onInteractionEvent ) { - private Atomic _shardCount = 0; // needs to be atomic due to the race situation here. + private OnceFlag _readyFlag = new(); private readonly ISettings _settings = settings ?? throw new ArgumentNullException(nameof(settings)); private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -54,8 +54,6 @@ private static string GetStatusText(string updateText) /// The client for the shard. public Task Invoke(DiscordSocketClient shard) { - _shardCount++; - _logger.Debug( "Shard '{0}' ready as '{0}#{1}'", shard.ShardId, @@ -63,12 +61,9 @@ public Task Invoke(DiscordSocketClient shard) _client.CurrentUser.Discriminator ); - if (_shardCount == _client.Shards.Count) - { - _shardCount = 0; - - _logger.Debug("Final shard ready!"); + Call.Once(ref _readyFlag, () => + { _client.MessageReceived += _onMessageEvent.Invoke; _client.InteractionCreated += _onInteractionEvent.Invoke; @@ -76,8 +71,8 @@ public Task Invoke(DiscordSocketClient shard) _client.SetStatusAsync(UserStatus.DoNotDisturb); _client.SetGameAsync(GetStatusText(text)); + }); - } return Task.CompletedTask; }