From b7d5a0b6a7d4a4c16add96f270d32a812ef981f3 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Sat, 10 May 2025 13:52:09 +0700 Subject: [PATCH] Fix bot management for delete and stop --- .github/workflows/caprover.yml | 30 ++++++++++++++----- .../Managing.Api.Workers.csproj | 2 +- ...cal.json => appsettings.SandboxLocal.json} | 0 .../Abstractions/IBotService.cs | 1 - src/Managing.Application/Bots/TradingBot.cs | 2 -- .../ManageBot/BotService.cs | 5 ---- .../ManageBot/LoadBackupBotCommandHandler.cs | 21 ++++++------- src/Managing.Domain/Bots/Bot.cs | 2 ++ .../BotRepository.cs | 4 +-- .../mollecules/TradesModal/TradesModal.tsx | 2 ++ 10 files changed, 41 insertions(+), 28 deletions(-) rename src/Managing.Api.Workers/{appsettings.ProdLocal.json => appsettings.SandboxLocal.json} (100%) diff --git a/.github/workflows/caprover.yml b/.github/workflows/caprover.yml index 243361b..bc90abf 100644 --- a/.github/workflows/caprover.yml +++ b/.github/workflows/caprover.yml @@ -10,13 +10,29 @@ jobs: steps: - name: Check out repository uses: actions/checkout@v4 - - name: Build and test your app (customize as needed) - run: | - # Add your build and test commands here - # For example: - # npm install - # npm run build - # npm run test + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Preset Image Name + run: echo "IMAGE_URL=$(echo ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:$(echo ${{ github.sha }} | cut -c1-7) | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Build and push Docker Image + uses: docker/build-push-action@v5 + with: + context: ./src/Managing.WebApp + file: ./src/Managing.WebApp/Dockerfile-web-ui-dev + push: true + tags: ${{ env.IMAGE_URL }} + + # - name: Create deploy.tar # uses: a7ul/tar-action@v1.1.0 # with: diff --git a/src/Managing.Api.Workers/Managing.Api.Workers.csproj b/src/Managing.Api.Workers/Managing.Api.Workers.csproj index fe039e5..e429e36 100644 --- a/src/Managing.Api.Workers/Managing.Api.Workers.csproj +++ b/src/Managing.Api.Workers/Managing.Api.Workers.csproj @@ -47,7 +47,7 @@ Always - + Always diff --git a/src/Managing.Api.Workers/appsettings.ProdLocal.json b/src/Managing.Api.Workers/appsettings.SandboxLocal.json similarity index 100% rename from src/Managing.Api.Workers/appsettings.ProdLocal.json rename to src/Managing.Api.Workers/appsettings.SandboxLocal.json diff --git a/src/Managing.Application/Abstractions/IBotService.cs b/src/Managing.Application/Abstractions/IBotService.cs index 93ede4b..e61923b 100644 --- a/src/Managing.Application/Abstractions/IBotService.cs +++ b/src/Managing.Application/Abstractions/IBotService.cs @@ -25,6 +25,5 @@ public interface IBotService Task StopBot(string botName); Task DeleteBot(string botName); Task RestartBot(string botName); - void DeleteBotBackup(string backupBotName); void ToggleIsForWatchingOnly(string botName); } \ No newline at end of file diff --git a/src/Managing.Application/Bots/TradingBot.cs b/src/Managing.Application/Bots/TradingBot.cs index 53fbbb2..8d06bc6 100644 --- a/src/Managing.Application/Bots/TradingBot.cs +++ b/src/Managing.Application/Bots/TradingBot.cs @@ -126,8 +126,6 @@ public class TradingBot : Bot, ITradingBot else { Account = account; - // Set the User property from the account - User = account.User; } } diff --git a/src/Managing.Application/ManageBot/BotService.cs b/src/Managing.Application/ManageBot/BotService.cs index 4ccc9d9..4fe64e2 100644 --- a/src/Managing.Application/ManageBot/BotService.cs +++ b/src/Managing.Application/ManageBot/BotService.cs @@ -232,11 +232,6 @@ namespace Managing.Application.ManageBot return Task.FromResult(BotStatus.Down.ToString()); } - public void DeleteBotBackup(string identifier) - { - _botRepository.DeleteBotBackup(identifier); - } - public void ToggleIsForWatchingOnly(string identifier) { if (_botTasks.TryGetValue(identifier, out var botTaskWrapper) && diff --git a/src/Managing.Application/ManageBot/LoadBackupBotCommandHandler.cs b/src/Managing.Application/ManageBot/LoadBackupBotCommandHandler.cs index 133dca0..4bd225e 100644 --- a/src/Managing.Application/ManageBot/LoadBackupBotCommandHandler.cs +++ b/src/Managing.Application/ManageBot/LoadBackupBotCommandHandler.cs @@ -44,39 +44,41 @@ public class LoadBackupBotCommandHandler : IRequestHandler b.Identifier == backupBot.Identifier); + activeBot = _botService.GetActiveBots() + .FirstOrDefault(b => b.Identifier == backupBot.Identifier); if (activeBot != null) { result[activeBot.Identifier] = BotStatus.Up; anyBackupStarted = true; - _logger.LogInformation("Backup bot {Identifier} started successfully.", backupBot.Identifier); + _logger.LogInformation("Backup bot {Identifier} started successfully.", + backupBot.Identifier); break; } - + attempts++; if (attempts < maxAttempts) { Thread.Sleep(1000); // Wait another second before next attempt } } - + if (activeBot == null) { result[backupBot.Identifier] = BotStatus.Down; - _logger.LogWarning("Backup bot {Identifier} failed to start after {MaxAttempts} attempts.", + _logger.LogWarning("Backup bot {Identifier} failed to start after {MaxAttempts} attempts.", backupBot.Identifier, maxAttempts); } } @@ -93,7 +95,6 @@ public class LoadBackupBotCommandHandler : IRequestHandler b.Name == botName); + var backup = await _botRepository.FindOneAsync(b => b.Identifier == identifier); await _botRepository.DeleteOneAsync(b => b.Id == backup.Id); } } \ No newline at end of file diff --git a/src/Managing.WebApp/src/components/mollecules/TradesModal/TradesModal.tsx b/src/Managing.WebApp/src/components/mollecules/TradesModal/TradesModal.tsx index 5be025d..f250b5f 100644 --- a/src/Managing.WebApp/src/components/mollecules/TradesModal/TradesModal.tsx +++ b/src/Managing.WebApp/src/components/mollecules/TradesModal/TradesModal.tsx @@ -24,6 +24,8 @@ const TradesModal: React.FC = ({ const [closingPosition, setClosingPosition] = useState(null) useEffect(() => { + console.log('strategyName', strategyName) + console.log('agentName', agentName) if (showModal && strategyName && agentName) { fetchStrategyData() }