Fix Worker-Cycle:

Periodic set last execution,
Print Running Worker-Names when done
This commit is contained in:
2025-07-03 22:48:06 +02:00
parent e8d612557f
commit 9743bb6e8e
3 changed files with 9 additions and 3 deletions

View File

@ -88,6 +88,8 @@ public abstract class BaseWorker : Identifiable
DateTime endTime = DateTime.UtcNow;
Log.Info($"Completed {this}\n\t{endTime.Subtract(startTime).TotalMilliseconds} ms");
this.State = WorkerExecutionState.Completed;
if(this is IPeriodic periodic)
periodic.LastExecution = DateTime.UtcNow;
});
task.Start();
this.State = WorkerExecutionState.Running;

View File

@ -2,7 +2,7 @@ namespace API.Workers;
public interface IPeriodic
{
protected DateTime LastExecution { get; set; }
internal DateTime LastExecution { get; set; }
public TimeSpan Interval { get; set; }
public DateTime NextExecution => LastExecution.Add(Interval);
public bool IsDue => NextExecution <= DateTime.UtcNow;