Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add log in agent refresh #406

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ public async Task<string> RefreshAgents()
var isAgentDeleted = _db.DeleteAgent(agent.Id);
if (isAgentDeleted)
{
await Task.Delay(100);
_db.BulkInsertAgents(new List<Agent> { agent });
_db.BulkInsertUserAgents(new List<UserAgent> { userAgent });
_db.BulkInsertAgentTasks(tasks);
refreshedAgents.Add(agent.Name);
_logger.LogInformation($"Agent {agent.Name} has been migrated.");
}
}
catch (Exception ex)
Expand All @@ -66,7 +68,7 @@ public async Task<string> RefreshAgents()
if (!refreshedAgents.IsNullOrEmpty())
{
Utilities.ClearCache();
refreshResult = $"Agents are migrated! {string.Join("\r\n", refreshedAgents)}";
refreshResult = $"Agents are migrated!\r\n{string.Join("\r\n", refreshedAgents)}";
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ public async Task UpdateAgent(Agent agent, AgentField updateField)

public async Task<string> UpdateAgentFromFile(string id)
{
string updateResult;
var agent = _db.GetAgent(id);
if (agent == null)
{
return $"Cannot find agent ${id}";
updateResult = $"Cannot find agent ${id}";
_logger.LogError(updateResult);
return updateResult;
}

var dbSettings = _services.GetRequiredService<BotSharpDatabaseSettings>();
Expand All @@ -57,7 +60,9 @@ public async Task<string> UpdateAgentFromFile(string id)
var foundAgent = FetchAgentFileById(agent.Id, filePath);
if (foundAgent == null)
{
return $"Cannot find agent {agent.Name} in file directory: {filePath}";
updateResult = $"Cannot find agent {agent.Name} in file directory: {filePath}";
_logger.LogError(updateResult);
return updateResult;
}

try
Expand All @@ -79,11 +84,16 @@ public async Task<string> UpdateAgentFromFile(string id)

_db.UpdateAgent(clonedAgent, AgentField.All);
Utilities.ClearCache();
return $"Agent {agent.Name} has been migrated!";

updateResult = $"Agent {agent.Name} has been migrated!";
_logger.LogInformation(updateResult);
return updateResult;
}
catch (Exception ex)
{
return $"Failed to migrate agent {agent.Name} in file directory {filePath}.\r\nError: {ex.Message}";
updateResult = $"Failed to migrate agent {agent.Name} in file directory {filePath}.\r\nError: {ex.Message}";
_logger.LogError(updateResult);
return updateResult;
}
}

Expand Down