jobs fixes
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.10.0</Version>
|
<Version>2.10.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -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,12 +24,19 @@ 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);
|
||||||
|
|
||||||
foreach (var job in jobs)
|
if (jobs.Any())
|
||||||
{
|
{
|
||||||
job.LastExecution = now;
|
BeforeExecute?.Invoke(this, EventArgs.Empty);
|
||||||
job.Execute(new(this));
|
|
||||||
|
foreach (var job in jobs)
|
||||||
|
{
|
||||||
|
job.LastExecution = now;
|
||||||
|
job.Execute(new(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterExecute?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Enabled)
|
if (Enabled)
|
||||||
|
|||||||
@@ -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'">
|
||||||
|
|||||||
Reference in New Issue
Block a user