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;
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()

View File

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

View File

@@ -2,6 +2,9 @@
public class JobCenter
{
public event EventHandler BeforeExecute;
public event EventHandler AfterExecute;
private readonly HashSet<Job> jobs = [];
private readonly System.Timers.Timer timerRepeat = new()
{
@@ -21,12 +24,19 @@ public class JobCenter
private void TimerRepeat_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
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);
foreach (var job in jobs)
if (jobs.Any())
{
job.LastExecution = now;
job.Execute(new(this));
BeforeExecute?.Invoke(this, EventArgs.Empty);
foreach (var job in jobs)
{
job.LastExecution = now;
job.Execute(new(this));
}
AfterExecute?.Invoke(this, EventArgs.Empty);
}
if (Enabled)

View File

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