Fix bot management for delete and stop
This commit is contained in:
30
.github/workflows/caprover.yml
vendored
30
.github/workflows/caprover.yml
vendored
@@ -10,13 +10,29 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Build and test your app (customize as needed)
|
|
||||||
run: |
|
- name: Set up Docker Buildx
|
||||||
# Add your build and test commands here
|
uses: docker/setup-buildx-action@v3
|
||||||
# For example:
|
|
||||||
# npm install
|
- name: Login to Container Registry
|
||||||
# npm run build
|
uses: docker/login-action@v3
|
||||||
# npm run test
|
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
|
# - name: Create deploy.tar
|
||||||
# uses: a7ul/tar-action@v1.1.0
|
# uses: a7ul/tar-action@v1.1.0
|
||||||
# with:
|
# with:
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
<Content Update="appsettings.Sandbox.json">
|
<Content Update="appsettings.Sandbox.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Update="appsettings.ProdLocal.json">
|
<Content Update="appsettings.SandboxLocal.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Update="appsettings.Production.json">
|
<Content Update="appsettings.Production.json">
|
||||||
|
|||||||
@@ -25,6 +25,5 @@ public interface IBotService
|
|||||||
Task<string> StopBot(string botName);
|
Task<string> StopBot(string botName);
|
||||||
Task<bool> DeleteBot(string botName);
|
Task<bool> DeleteBot(string botName);
|
||||||
Task<string> RestartBot(string botName);
|
Task<string> RestartBot(string botName);
|
||||||
void DeleteBotBackup(string backupBotName);
|
|
||||||
void ToggleIsForWatchingOnly(string botName);
|
void ToggleIsForWatchingOnly(string botName);
|
||||||
}
|
}
|
||||||
@@ -126,8 +126,6 @@ public class TradingBot : Bot, ITradingBot
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Account = account;
|
Account = account;
|
||||||
// Set the User property from the account
|
|
||||||
User = account.User;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -232,11 +232,6 @@ namespace Managing.Application.ManageBot
|
|||||||
return Task.FromResult(BotStatus.Down.ToString());
|
return Task.FromResult(BotStatus.Down.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteBotBackup(string identifier)
|
|
||||||
{
|
|
||||||
_botRepository.DeleteBotBackup(identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ToggleIsForWatchingOnly(string identifier)
|
public void ToggleIsForWatchingOnly(string identifier)
|
||||||
{
|
{
|
||||||
if (_botTasks.TryGetValue(identifier, out var botTaskWrapper) &&
|
if (_botTasks.TryGetValue(identifier, out var botTaskWrapper) &&
|
||||||
|
|||||||
@@ -44,39 +44,41 @@ public class LoadBackupBotCommandHandler : IRequestHandler<LoadBackupBotCommand,
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("No active instance found for bot {Identifier}. Starting backup...",
|
_logger.LogInformation("No active instance found for bot {Identifier}. Starting backup...",
|
||||||
backupBot.Identifier);
|
backupBot.Identifier);
|
||||||
|
|
||||||
// Start the bot from backup
|
// Start the bot from backup
|
||||||
_botService.StartBotFromBackup(backupBot);
|
_botService.StartBotFromBackup(backupBot);
|
||||||
|
|
||||||
// Wait a short time to allow the bot to initialize
|
// Wait a short time to allow the bot to initialize
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
// Try to get the active bot multiple times to ensure it's properly started
|
// Try to get the active bot multiple times to ensure it's properly started
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
const int maxAttempts = 5;
|
const int maxAttempts = 5;
|
||||||
|
|
||||||
while (attempts < maxAttempts)
|
while (attempts < maxAttempts)
|
||||||
{
|
{
|
||||||
activeBot = _botService.GetActiveBots().FirstOrDefault(b => b.Identifier == backupBot.Identifier);
|
activeBot = _botService.GetActiveBots()
|
||||||
|
.FirstOrDefault(b => b.Identifier == backupBot.Identifier);
|
||||||
if (activeBot != null)
|
if (activeBot != null)
|
||||||
{
|
{
|
||||||
result[activeBot.Identifier] = BotStatus.Up;
|
result[activeBot.Identifier] = BotStatus.Up;
|
||||||
anyBackupStarted = true;
|
anyBackupStarted = true;
|
||||||
_logger.LogInformation("Backup bot {Identifier} started successfully.", backupBot.Identifier);
|
_logger.LogInformation("Backup bot {Identifier} started successfully.",
|
||||||
|
backupBot.Identifier);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
attempts++;
|
attempts++;
|
||||||
if (attempts < maxAttempts)
|
if (attempts < maxAttempts)
|
||||||
{
|
{
|
||||||
Thread.Sleep(1000); // Wait another second before next attempt
|
Thread.Sleep(1000); // Wait another second before next attempt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeBot == null)
|
if (activeBot == null)
|
||||||
{
|
{
|
||||||
result[backupBot.Identifier] = BotStatus.Down;
|
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);
|
backupBot.Identifier, maxAttempts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +95,6 @@ public class LoadBackupBotCommandHandler : IRequestHandler<LoadBackupBotCommand,
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error loading bot {Identifier}. Deleting its backup.", backupBot.Identifier);
|
_logger.LogError(ex, "Error loading bot {Identifier}. Deleting its backup.", backupBot.Identifier);
|
||||||
_botService.DeleteBotBackup(backupBot.Identifier);
|
|
||||||
result[backupBot.Identifier] = BotStatus.Down;
|
result[backupBot.Identifier] = BotStatus.Down;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,12 +78,14 @@ namespace Managing.Domain.Bots
|
|||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
Status = BotStatus.Down;
|
Status = BotStatus.Down;
|
||||||
|
SaveBackup();
|
||||||
CancellationToken.Cancel();
|
CancellationToken.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Restart()
|
public void Restart()
|
||||||
{
|
{
|
||||||
Status = BotStatus.Up;
|
Status = BotStatus.Up;
|
||||||
|
SaveBackup();
|
||||||
StartupTime = DateTime.UtcNow; // Update the startup time when the bot is restarted
|
StartupTime = DateTime.UtcNow; // Update the startup time when the bot is restarted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ public class BotRepository : IBotRepository
|
|||||||
_botRepository.Update(dto);
|
_botRepository.Update(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteBotBackup(string botName)
|
public async Task DeleteBotBackup(string identifier)
|
||||||
{
|
{
|
||||||
var backup = await _botRepository.FindOneAsync(b => b.Name == botName);
|
var backup = await _botRepository.FindOneAsync(b => b.Identifier == identifier);
|
||||||
await _botRepository.DeleteOneAsync(b => b.Id == backup.Id);
|
await _botRepository.DeleteOneAsync(b => b.Id == backup.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,8 @@ const TradesModal: React.FC<TradesModalProps> = ({
|
|||||||
const [closingPosition, setClosingPosition] = useState<string | null>(null)
|
const [closingPosition, setClosingPosition] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log('strategyName', strategyName)
|
||||||
|
console.log('agentName', agentName)
|
||||||
if (showModal && strategyName && agentName) {
|
if (showModal && strategyName && agentName) {
|
||||||
fetchStrategyData()
|
fetchStrategyData()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user