Improved Indexer worker list result

This commit is contained in:
2025-07-19 21:21:28 +02:00
parent 87f644bebb
commit 07fa8945dc
4 changed files with 99 additions and 18 deletions

View File

@@ -41,7 +41,8 @@ public class CallsController : ControllerBase
CallListResult callListResult = new() CallListResult callListResult = new()
{ {
CallConfig = call.CallConfig, CallConfig = call.CallConfig,
IsRunning = call.IsRunning, IsActive = call.IsEnabled,
IsExecuting = call.IsExecuting,
LastExecution = call.LastExecution, LastExecution = call.LastExecution,
LastSuccessfulExecution = call.LastSuccessfulExecution, LastSuccessfulExecution = call.LastSuccessfulExecution,
HealthStatus = call.HealthCheck().Status.ToString() HealthStatus = call.HealthCheck().Status.ToString()

View File

@@ -35,6 +35,9 @@ public class WorkerController : ControllerBase
{ {
Name = worker.Name, Name = worker.Name,
Script = worker.Config.Script, Script = worker.Config.Script,
IsExecuting = worker.IsExecuting,
LastExecution = worker.LastExecution,
LastSuccessfulExecution = worker.LastSuccessfulExecution,
HealthStatus = worker.HealthCheck().Status.ToString() HealthStatus = worker.HealthCheck().Status.ToString()
}; };
workerListResultList.Add(workerListResult); workerListResultList.Add(workerListResult);
@@ -65,7 +68,26 @@ public class WorkerController : ControllerBase
} }
_logger.LogInformation("triggering worker {name}.", [name]); _logger.LogInformation("triggering worker {name}.", [name]);
ManualTriggerCallbackInfos callbackInfos = new(); ManualTriggerCallbackInfos callbackInfos = new();
worker.Scriptable.Update(callbackInfos); lock (worker.Scriptable)
{
worker.IsExecuting = true;
worker.Scriptable.Update(callbackInfos);
worker.IsExecuting = false;
DateTime beforeExecution = DateTime.Now;
worker.IsExecuting = true;
try
{
worker.Scriptable.Update(callbackInfos);
}
finally
{
worker.IsExecuting = false;
worker.LastExecution = beforeExecution;
}
DateTime afterExecution = DateTime.Now;
WorkerCollection.UpdateWorkerTimestamps(worker, beforeExecution, afterExecution);
}
_logger.LogInformation("triggered worker {name}.", [name]); _logger.LogInformation("triggered worker {name}.", [name]);
return new WorkerTriggerUpdateResult { Success = true }; return new WorkerTriggerUpdateResult { Success = true };

View File

@@ -79,9 +79,20 @@ public class WorkerCollection
{ {
try try
{ {
call.LastExecution = DateTime.Now; DateTime beforeExecution = DateTime.Now;
worker.Scriptable.Update(new IntervalCallbackInfos() { sender = sender, e = e }); call.IsExecuting = true;
call.LastSuccessfulExecution = DateTime.Now; try
{
worker.Scriptable.Update(new IntervalCallbackInfos() { sender = sender, e = e });
}
finally
{
call.IsExecuting = false;
call.LastExecution = beforeExecution;
worker.LastExecution = beforeExecution;
}
DateTime afterExecution = DateTime.Now;
UpdateCallAndWorkerTimestamps(call, worker, beforeExecution, afterExecution);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -106,6 +117,32 @@ public class WorkerCollection
} }
} }
public static void UpdateCallAndWorkerTimestamps(ICall call, Worker worker, DateTime beforeExecution, DateTime afterExecution)
{
UpdateCallTimestamps(call, beforeExecution, afterExecution);
UpdateWorkerTimestamps(worker, beforeExecution, afterExecution);
}
public static void UpdateCallTimestamps(ICall call, DateTime beforeExecution, DateTime afterExecution)
{
call.LastSuccessfulExecution = GetNewestDateTime(call.LastSuccessfulExecution, afterExecution);
}
public static void UpdateWorkerTimestamps(Worker worker, DateTime beforeExecution, DateTime afterExecution)
{
worker.LastSuccessfulExecution = GetNewestDateTime(worker.LastSuccessfulExecution, afterExecution);
}
public static DateTime? GetNewestDateTime(DateTime? preexistingDateTime, DateTime incomingDateTime)
{
if (preexistingDateTime is null || preexistingDateTime.Value.CompareTo(incomingDateTime) < 0)
{
return incomingDateTime;
}
return preexistingDateTime;
}
public IScriptable GetScriptable(ScriptToolSet toolSet) public IScriptable GetScriptable(ScriptToolSet toolSet)
{ {
string fileName = toolSet.filePath; string fileName = toolSet.filePath;
@@ -129,12 +166,16 @@ public class Worker
public WorkerConfig Config { get; set; } public WorkerConfig Config { get; set; }
public IScriptable Scriptable { get; set; } public IScriptable Scriptable { get; set; }
public List<ICall> Calls { get; set; } public List<ICall> Calls { get; set; }
public bool IsExecuting { get; set; }
public DateTime? LastExecution { get; set; }
public DateTime? LastSuccessfulExecution { get; set; }
public Worker(string Name, WorkerConfig workerConfig, IScriptable scriptable) public Worker(string name, WorkerConfig workerConfig, IScriptable scriptable)
{ {
this.Name = Name; Name = name;
this.Config = workerConfig; Config = workerConfig;
this.Scriptable = scriptable; Scriptable = scriptable;
IsExecuting = false;
Calls = []; Calls = [];
} }
@@ -188,7 +229,8 @@ public interface ICall
public HealthCheckResult HealthCheck(); public HealthCheckResult HealthCheck();
public void Start(); public void Start();
public void Stop(); public void Stop();
public bool IsRunning { get; set; } public bool IsEnabled { get; set; }
public bool IsExecuting { get; set; }
public CallConfig CallConfig { get; set; } public CallConfig CallConfig { get; set; }
public DateTime? LastExecution { get; set; } public DateTime? LastExecution { get; set; }
public DateTime? LastSuccessfulExecution { get; set; } public DateTime? LastSuccessfulExecution { get; set; }
@@ -199,7 +241,8 @@ public class IntervalCall : ICall
public System.Timers.Timer Timer; public System.Timers.Timer Timer;
public IScriptable Scriptable; public IScriptable Scriptable;
public ILogger _logger; public ILogger _logger;
public bool IsRunning { get; set; } public bool IsEnabled { get; set; }
public bool IsExecuting { get; set; }
public CallConfig CallConfig { get; set; } public CallConfig CallConfig { get; set; }
public DateTime? LastExecution { get; set; } public DateTime? LastExecution { get; set; }
public DateTime? LastSuccessfulExecution { get; set; } public DateTime? LastSuccessfulExecution { get; set; }
@@ -210,20 +253,21 @@ public class IntervalCall : ICall
Scriptable = scriptable; Scriptable = scriptable;
_logger = logger; _logger = logger;
CallConfig = callConfig; CallConfig = callConfig;
IsRunning = true; IsEnabled = true;
IsExecuting = false;
} }
public void Start() public void Start()
{ {
Timer.Start(); Timer.Start();
IsRunning = true; IsEnabled = true;
} }
public void Stop() public void Stop()
{ {
Scriptable.Stop(); Scriptable.Stop();
Timer.Stop(); Timer.Stop();
IsRunning = false; IsEnabled = false;
} }
public HealthCheckResult HealthCheck() public HealthCheckResult HealthCheck()
@@ -249,7 +293,8 @@ public class IntervalCall : ICall
public class ScheduleCall : ICall public class ScheduleCall : ICall
{ {
public bool IsRunning { get; set; } public bool IsEnabled { get; set; }
public bool IsExecuting { get; set; }
public CallConfig CallConfig { get; set; } public CallConfig CallConfig { get; set; }
public DateTime? LastExecution { get; set; } public DateTime? LastExecution { get; set; }
public DateTime? LastSuccessfulExecution { get; set; } public DateTime? LastSuccessfulExecution { get; set; }
@@ -257,6 +302,8 @@ public class ScheduleCall : ICall
public ScheduleCall(CallConfig callConfig) public ScheduleCall(CallConfig callConfig)
{ {
CallConfig = callConfig; CallConfig = callConfig;
IsEnabled = true;
IsExecuting = false;
} }
public void Start() public void Start()
@@ -275,7 +322,8 @@ public class ScheduleCall : ICall
public class FileUpdateCall : ICall public class FileUpdateCall : ICall
{ {
public bool IsRunning { get; set; } public bool IsEnabled { get; set; }
public bool IsExecuting { get; set; }
public CallConfig CallConfig { get; set; } public CallConfig CallConfig { get; set; }
public DateTime? LastExecution { get; set; } public DateTime? LastExecution { get; set; }
public DateTime? LastSuccessfulExecution { get; set; } public DateTime? LastSuccessfulExecution { get; set; }
@@ -283,6 +331,8 @@ public class FileUpdateCall : ICall
public FileUpdateCall(CallConfig callConfig) public FileUpdateCall(CallConfig callConfig)
{ {
CallConfig = callConfig; CallConfig = callConfig;
IsEnabled = true;
IsExecuting = false;
} }
public void Start() public void Start()

View File

@@ -17,6 +17,12 @@ public class WorkerListResult
public required string Name { get; set; } public required string Name { get; set; }
[JsonPropertyName("Script")] [JsonPropertyName("Script")]
public required string Script { get; set; } public required string Script { get; set; }
[JsonPropertyName("IsExecuting")]
public required bool IsExecuting { get; set; }
[JsonPropertyName("LastExecution")]
public required DateTime? LastExecution { get; set; }
[JsonPropertyName("LastSuccessfulExecution")]
public required DateTime? LastSuccessfulExecution { get; set; }
[JsonPropertyName("HealthStatus")] [JsonPropertyName("HealthStatus")]
public required string HealthStatus { get; set; } public required string HealthStatus { get; set; }
} }
@@ -33,8 +39,10 @@ public class CallListResult
{ {
[JsonPropertyName("CallConfig")] [JsonPropertyName("CallConfig")]
public required CallConfig CallConfig { get; set; } public required CallConfig CallConfig { get; set; }
[JsonPropertyName("IsRunning")] [JsonPropertyName("IsActive")]
public required bool IsRunning { get; set; } public required bool IsActive { get; set; }
[JsonPropertyName("IsExecuting")]
public required bool IsExecuting { get; set; }
[JsonPropertyName("LastExecution")] [JsonPropertyName("LastExecution")]
public required DateTime? LastExecution { get; set; } public required DateTime? LastExecution { get; set; }
[JsonPropertyName("LastSuccessfulExecution")] [JsonPropertyName("LastSuccessfulExecution")]