jobs fixes
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>2.10.0</Version>
|
||||
<Version>2.10.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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);
|
||||
|
||||
foreach (var job in jobs)
|
||||
var jobs = this.jobs.Where(n => n.LastExecution + n.Interval < now);
|
||||
|
||||
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)
|
||||
|
||||
@@ -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'">
|
||||
|
||||
Reference in New Issue
Block a user