From b46c543d98448a95ff6fff3b182b07a0be5fee27 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Sun, 31 Aug 2025 15:22:44 +0200 Subject: [PATCH] Added CancellationToken renewal --- src/Indexer/Controllers/CallsController.cs | 12 ++++++++++++ src/Indexer/Worker.cs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Indexer/Controllers/CallsController.cs b/src/Indexer/Controllers/CallsController.cs index 37a6e70..caed389 100644 --- a/src/Indexer/Controllers/CallsController.cs +++ b/src/Indexer/Controllers/CallsController.cs @@ -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 }; diff --git a/src/Indexer/Worker.cs b/src/Indexer/Worker.cs index 113fd47..7dee10c 100644 --- a/src/Indexer/Worker.cs +++ b/src/Indexer/Worker.cs @@ -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 Calls { get; set; } public bool IsExecuting { get; set; } public DateTime? LastExecution { get; set; }