Add stats for kaigen

This commit is contained in:
2025-04-24 22:40:10 +07:00
parent 86692b60fa
commit 1d14d31af2
13 changed files with 483 additions and 8 deletions

View File

@@ -16,6 +16,10 @@ namespace Managing.Domain.Bots
public int Interval { get; set; }
public BotStatus Status { get; set; }
public User User { get; set; }
/// <summary>
/// The time when the bot was started
/// </summary>
public DateTime StartupTime { get; private set; }
private CancellationTokenSource CancellationToken { get; set; }
public Bot(string name)
@@ -26,11 +30,13 @@ namespace Managing.Domain.Bots
CancellationToken = new CancellationTokenSource();
ExecutionCount = 0;
Interval = 3000;
StartupTime = DateTime.MinValue; // Initialize with minimum value to indicate it hasn't been started yet
}
public virtual void Start()
{
Status = BotStatus.Up;
StartupTime = DateTime.UtcNow; // Record the startup time when the bot is started
}
public async Task InitWorker(Func<Task> action)
@@ -76,6 +82,7 @@ namespace Managing.Domain.Bots
public void Restart()
{
Status = BotStatus.Up;
StartupTime = DateTime.UtcNow; // Update the startup time when the bot is restarted
}
public string GetStatus()
@@ -87,6 +94,18 @@ namespace Managing.Domain.Bots
{
return Name;
}
/// <summary>
/// Gets the total runtime of the bot since it was started
/// </summary>
/// <returns>TimeSpan representing the runtime, or TimeSpan.Zero if the bot is not running</returns>
public TimeSpan GetRuntime()
{
if (Status != BotStatus.Up || StartupTime == DateTime.MinValue)
return TimeSpan.Zero;
return DateTime.UtcNow - StartupTime;
}
public abstract void SaveBackup();
public abstract void LoadBackup(BotBackup backup);

View File

@@ -8,6 +8,11 @@
void Restart();
string GetStatus();
string GetName();
/// <summary>
/// Gets the total runtime of the bot since it was started
/// </summary>
/// <returns>TimeSpan representing the runtime, or TimeSpan.Zero if the bot is not running</returns>
TimeSpan GetRuntime();
void SaveBackup();
void LoadBackup(BotBackup backup);
}