Improve hot reload logic with enhanced logging and semaphore management

This commit is contained in:
Thorsten Sommer 2025-04-27 15:33:33 +02:00
parent a3a1483c84
commit 2492a588b7
No known key found for this signature in database
GPG Key ID: B0B7E2FC074BF1F5

View File

@ -22,15 +22,23 @@ public static partial class PluginFactory
HOT_RELOAD_WATCHER.Filter = "*.lua"; HOT_RELOAD_WATCHER.Filter = "*.lua";
HOT_RELOAD_WATCHER.Changed += async (_, args) => HOT_RELOAD_WATCHER.Changed += async (_, args) =>
{ {
var changeType = args.ChangeType.ToString().ToLowerInvariant();
if (!await HOT_RELOAD_SEMAPHORE.WaitAsync(0)) if (!await HOT_RELOAD_SEMAPHORE.WaitAsync(0))
{ {
LOG.LogInformation($"File changed ({args.ChangeType}): {args.FullPath}. Already processing another change."); LOG.LogInformation($"File changed ({changeType}): {args.FullPath}. Already processing another change.");
return; return;
} }
LOG.LogInformation($"File changed ({args.ChangeType}): {args.FullPath}. Reloading plugins..."); try
await LoadAll(); {
await messageBus.SendMessage<bool>(null, Event.PLUGINS_RELOADED); LOG.LogInformation($"File changed ({changeType}): {args.FullPath}. Reloading plugins...");
await LoadAll();
await messageBus.SendMessage<bool>(null, Event.PLUGINS_RELOADED);
}
finally
{
HOT_RELOAD_SEMAPHORE.Release();
}
}; };
HOT_RELOAD_WATCHER.EnableRaisingEvents = true; HOT_RELOAD_WATCHER.EnableRaisingEvents = true;