Renamed IScriptable to IScriptContainer, added Stop() function to Calls
This commit is contained in:
@@ -38,6 +38,11 @@ public class RunOnceCall : ICall
|
|||||||
|
|
||||||
public void Dispose() {}
|
public void Dispose() {}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
Worker.Scriptable.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
private async void IndexAsync()
|
private async void IndexAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -73,7 +78,7 @@ public class RunOnceCall : ICall
|
|||||||
public class IntervalCall : ICall
|
public class IntervalCall : ICall
|
||||||
{
|
{
|
||||||
public System.Timers.Timer Timer;
|
public System.Timers.Timer Timer;
|
||||||
public IScriptable Scriptable;
|
public IScriptContainer Scriptable;
|
||||||
public ILogger _logger;
|
public ILogger _logger;
|
||||||
public bool IsEnabled { get; set; }
|
public bool IsEnabled { get; set; }
|
||||||
public bool IsExecuting { get; set; }
|
public bool IsExecuting { get; set; }
|
||||||
@@ -145,6 +150,11 @@ public class IntervalCall : ICall
|
|||||||
Timer.Dispose();
|
Timer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
Scriptable.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
public HealthCheckResult HealthCheck()
|
public HealthCheckResult HealthCheck()
|
||||||
{
|
{
|
||||||
if (!Scriptable.UpdateInfo.Successful)
|
if (!Scriptable.UpdateInfo.Successful)
|
||||||
@@ -241,6 +251,11 @@ public class ScheduleCall : ICall
|
|||||||
Scheduler.DeleteJob(JobKey);
|
Scheduler.DeleteJob(JobKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
Worker.Scriptable.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task CreateJob()
|
private async Task CreateJob()
|
||||||
{
|
{
|
||||||
if (CallConfig.Schedule is null)
|
if (CallConfig.Schedule is null)
|
||||||
@@ -341,6 +356,11 @@ public class FileUpdateCall : ICall
|
|||||||
_watcher.Dispose();
|
_watcher.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
Worker.Scriptable.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnFileChanged(object sender, FileSystemEventArgs e)
|
private void OnFileChanged(object sender, FileSystemEventArgs e)
|
||||||
{
|
{
|
||||||
if (!IsEnabled)
|
if (!IsEnabled)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public interface ICall
|
|||||||
public void Enable();
|
public void Enable();
|
||||||
public void Disable();
|
public void Disable();
|
||||||
public void Dispose();
|
public void Dispose();
|
||||||
|
public void Stop();
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public bool IsEnabled { get; set; }
|
public bool IsEnabled { get; set; }
|
||||||
public bool IsExecuting { get; set; }
|
public bool IsExecuting { get; set; }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Indexer.Models;
|
namespace Indexer.Models;
|
||||||
|
|
||||||
public interface IScriptable
|
public interface IScriptContainer
|
||||||
{
|
{
|
||||||
ScriptToolSet ToolSet { get; set; }
|
ScriptToolSet ToolSet { get; set; }
|
||||||
ScriptUpdateInfo UpdateInfo { get; set; }
|
ScriptUpdateInfo UpdateInfo { get; set; }
|
||||||
@@ -5,7 +5,7 @@ using Indexer.Models;
|
|||||||
|
|
||||||
namespace Indexer.ScriptContainers;
|
namespace Indexer.ScriptContainers;
|
||||||
|
|
||||||
public class CSharpScriptable : IScriptable
|
public class CSharpScriptable : IScriptContainer
|
||||||
{
|
{
|
||||||
public ScriptToolSet ToolSet { get; set; }
|
public ScriptToolSet ToolSet { get; set; }
|
||||||
public ScriptUpdateInfo UpdateInfo { get; set; }
|
public ScriptUpdateInfo UpdateInfo { get; set; }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using Indexer.Models;
|
|||||||
|
|
||||||
namespace Indexer.ScriptContainers;
|
namespace Indexer.ScriptContainers;
|
||||||
|
|
||||||
public class PythonScriptable : IScriptable
|
public class PythonScriptable : IScriptContainer
|
||||||
{
|
{
|
||||||
public ScriptToolSet ToolSet { get; set; }
|
public ScriptToolSet ToolSet { get; set; }
|
||||||
public PyObject? pyToolSet;
|
public PyObject? pyToolSet;
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ public class Worker
|
|||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public WorkerConfig Config { get; set; }
|
public WorkerConfig Config { get; set; }
|
||||||
public IScriptable Scriptable { get; set; }
|
public IScriptContainer Scriptable { get; set; }
|
||||||
public List<ICall> Calls { get; set; }
|
public List<ICall> Calls { get; set; }
|
||||||
public bool IsExecuting { get; set; }
|
public bool IsExecuting { get; set; }
|
||||||
public DateTime? LastExecution { get; set; }
|
public DateTime? LastExecution { get; set; }
|
||||||
public DateTime? LastSuccessfulExecution { get; set; }
|
public DateTime? LastSuccessfulExecution { get; set; }
|
||||||
|
|
||||||
public Worker(string name, WorkerConfig workerConfig, IScriptable scriptable)
|
public Worker(string name, WorkerConfig workerConfig, IScriptContainer scriptable)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Config = workerConfig;
|
Config = workerConfig;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class WorkerManager
|
|||||||
return preexistingDateTime;
|
return preexistingDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IScriptable GetScriptable(ScriptToolSet toolSet)
|
public IScriptContainer GetScriptable(ScriptToolSet toolSet)
|
||||||
{
|
{
|
||||||
string fileName = toolSet.FilePath ?? throw new IndexerConfigurationException($"\"Script\" not set for Worker \"{toolSet.Name}\"");
|
string fileName = toolSet.FilePath ?? throw new IndexerConfigurationException($"\"Script\" not set for Worker \"{toolSet.Name}\"");
|
||||||
foreach (Type type in types)
|
foreach (Type type in types)
|
||||||
@@ -115,7 +115,7 @@ public class WorkerManager
|
|||||||
bool? isInstance = method is not null ? (bool?)method.Invoke(null, [fileName]) : null;
|
bool? isInstance = method is not null ? (bool?)method.Invoke(null, [fileName]) : null;
|
||||||
if (isInstance == true)
|
if (isInstance == true)
|
||||||
{
|
{
|
||||||
IScriptable? instance = (IScriptable?)Activator.CreateInstance(type, [toolSet, _logger]);
|
IScriptContainer? instance = (IScriptContainer?)Activator.CreateInstance(type, [toolSet, _logger]);
|
||||||
if (instance is null)
|
if (instance is null)
|
||||||
{
|
{
|
||||||
_logger.LogError("Unable to initialize script: \"{fileName}\"", fileName);
|
_logger.LogError("Unable to initialize script: \"{fileName}\"", fileName);
|
||||||
|
|||||||
Reference in New Issue
Block a user