Add startuptime and update creationDate

This commit is contained in:
2025-07-09 18:30:23 +07:00
parent 387948a107
commit 0c1184a22d
11 changed files with 85 additions and 38 deletions

View File

@@ -17,9 +17,14 @@ namespace Managing.Domain.Bots
public User User { get; set; }
/// <summary>
/// The time when the bot was started
/// The time when the bot was first started (creation date)
/// </summary>
public DateTime StartupTime { get; private set; }
public DateTime StartupTime { get; protected set; }
/// <summary>
/// The time when the bot was created
/// </summary>
public DateTime CreateDate { get; protected set; }
private CancellationTokenSource CancellationToken { get; set; }
@@ -31,13 +36,14 @@ 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
CreateDate = DateTime.UtcNow; // Set the creation time when the bot is instantiated
StartupTime = DateTime.UtcNow; // Set the startup time to creation date initially
}
public virtual void Start()
{
Status = BotStatus.Up;
StartupTime = DateTime.UtcNow; // Record the startup time when the bot is started
// StartupTime remains unchanged on first start (it's already set to creation date)
}
public async Task InitWorker(Func<Task> action)
@@ -105,7 +111,7 @@ namespace Managing.Domain.Bots
/// <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)
if (Status != BotStatus.Up)
return TimeSpan.Zero;
return DateTime.UtcNow - StartupTime;

View File

@@ -9,4 +9,5 @@ public class BotBackup
public User User { get; set; }
public string Data { get; set; }
public BotStatus LastStatus { get; set; }
public DateTime CreateDate { get; set; }
}

View File

@@ -18,6 +18,11 @@ namespace Managing.Domain.Bots
/// <returns>TimeSpan representing the runtime, or TimeSpan.Zero if the bot is not running</returns>
TimeSpan GetRuntime();
/// <summary>
/// The time when the bot was first started (creation date)
/// </summary>
DateTime StartupTime { get; }
string Identifier { get; set; }
void SaveBackup();
void LoadBackup(BotBackup backup);