Added CancellationToken renewal

This commit is contained in:
2025-08-31 15:22:44 +02:00
parent 14a6acf50f
commit b46c543d98
2 changed files with 13 additions and 1 deletions

View File

@@ -64,6 +64,12 @@ public class CallsController : ControllerBase
}
if (callName is null)
{
if (worker.ScriptContainer.ToolSet.CancellationToken.IsCancellationRequested)
{
worker.CancellationTokenSource.Dispose();
worker.CancellationTokenSource = new CancellationTokenSource();
worker.ScriptContainer.ToolSet.CancellationToken = worker.CancellationTokenSource.Token;
}
_logger.LogInformation("Starting calls in worker {workerName}.", [workerName]);
foreach (ICall call in worker.Calls)
{
@@ -81,6 +87,12 @@ public class CallsController : ControllerBase
return new CallEnableResult { Success = false };
}
_logger.LogInformation("Starting call {callName} in worker {workerName}.", [callName, workerName]);
if (worker.ScriptContainer.ToolSet.CancellationToken.IsCancellationRequested)
{
worker.CancellationTokenSource.Dispose();
worker.CancellationTokenSource = new CancellationTokenSource();
worker.ScriptContainer.ToolSet.CancellationToken = worker.CancellationTokenSource.Token;
}
call.Enable();
}
return new CallEnableResult { Success = true };

View File

@@ -6,7 +6,7 @@ public class Worker
public string Name { get; set; }
public WorkerConfig Config { get; set; }
public IScriptContainer ScriptContainer { get; set; }
public CancellationTokenSource CancellationTokenSource { get; }
public CancellationTokenSource CancellationTokenSource { get; set; }
public List<ICall> Calls { get; set; }
public bool IsExecuting { get; set; }
public DateTime? LastExecution { get; set; }