jobs fixes

This commit is contained in:
Pilzinsel64
2025-11-21 10:01:55 +01:00
parent f53145d62e
commit 666126808d
4 changed files with 29 additions and 7 deletions

View File

@@ -66,6 +66,18 @@ public class ApiServer : IApiServer
{ {
ApiUrl = apiUrl; ApiUrl = apiUrl;
this.httpListener = httpListener ?? CreateDefaultHttpListener(); this.httpListener = httpListener ?? CreateDefaultHttpListener();
Jobs.BeforeExecute += Jobs_BeforeExecute;
Jobs.AfterExecute += Jobs_AfterExecute;
}
private void Jobs_BeforeExecute(object? sender, EventArgs e)
{
ResetManager();
}
private void Jobs_AfterExecute(object? sender, EventArgs e)
{
ResetManager();
} }
private IDataManager GetManager() private IDataManager GetManager()

View File

@@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<Version>2.10.0</Version> <Version>2.10.1</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -2,6 +2,9 @@
public class JobCenter public class JobCenter
{ {
public event EventHandler BeforeExecute;
public event EventHandler AfterExecute;
private readonly HashSet<Job> jobs = []; private readonly HashSet<Job> jobs = [];
private readonly System.Timers.Timer timerRepeat = new() private readonly System.Timers.Timer timerRepeat = new()
{ {
@@ -21,7 +24,11 @@ public class JobCenter
private void TimerRepeat_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void TimerRepeat_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
var now = DateTime.Now; var now = DateTime.Now;
var jobs = this.jobs.Where(n => n.LastExecution + n.Interval > now); var jobs = this.jobs.Where(n => n.LastExecution + n.Interval < now);
if (jobs.Any())
{
BeforeExecute?.Invoke(this, EventArgs.Empty);
foreach (var job in jobs) foreach (var job in jobs)
{ {
@@ -29,6 +36,9 @@ public class JobCenter
job.Execute(new(this)); job.Execute(new(this));
} }
AfterExecute?.Invoke(this, EventArgs.Empty);
}
if (Enabled) if (Enabled)
timerRepeat.Start(); timerRepeat.Start();
} }

View File

@@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>annotations</Nullable> <Nullable>annotations</Nullable>
<Version>2.6.1</Version> <Version>2.6.2</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> <PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">