Browse Source

fix: Streamline job deletion and enhance exception handling in TickerQ background worker manager

pull/25066/head
maliming 2 weeks ago
parent
commit
43e7365e22
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 9
      framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzDynamicBackgroundWorkerManager.cs
  2. 27
      framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/TickerQDynamicBackgroundWorkerManager.cs

9
framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzDynamicBackgroundWorkerManager.cs

@ -71,13 +71,10 @@ public class QuartzDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMana
} }
var jobKey = new JobKey($"DynamicWorker:{workerName}"); var jobKey = new JobKey($"DynamicWorker:{workerName}");
var deleted = await Scheduler.DeleteJob(jobKey, cancellationToken); await Scheduler.DeleteJob(jobKey, cancellationToken);
if (deleted) HandlerRegistry.Unregister(workerName);
{
HandlerRegistry.Unregister(workerName);
}
return deleted; return true;
} }
public virtual async Task<bool> UpdateScheduleAsync( public virtual async Task<bool> UpdateScheduleAsync(

27
framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/TickerQDynamicBackgroundWorkerManager.cs

@ -1,12 +1,14 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using TickerQ.Utilities.Entities; using TickerQ.Utilities.Entities;
using TickerQ.Utilities.Enums; using TickerQ.Utilities.Enums;
using TickerQ.Utilities.Interfaces.Managers; using TickerQ.Utilities.Interfaces.Managers;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.TickerQ; using Volo.Abp.TickerQ;
namespace Volo.Abp.BackgroundWorkers.TickerQ; namespace Volo.Abp.BackgroundWorkers.TickerQ;
@ -57,9 +59,19 @@ public class TickerQDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMan
return; return;
} }
await registeredHandler( try
new DynamicBackgroundWorkerExecutionContext(workerName, serviceProvider), {
tickerCancellationToken); await registeredHandler(
new DynamicBackgroundWorkerExecutionContext(workerName, serviceProvider),
tickerCancellationToken);
}
catch (Exception ex)
{
await serviceProvider.GetRequiredService<IExceptionNotifier>()
.NotifyAsync(new ExceptionNotificationContext(ex));
throw;
}
}, 0); }, 0);
AbpTickerQBackgroundWorkersProvider.BackgroundWorkers[functionName] = new AbpTickerQCronBackgroundWorker AbpTickerQBackgroundWorkersProvider.BackgroundWorkers[functionName] = new AbpTickerQCronBackgroundWorker
@ -92,9 +104,12 @@ public class TickerQDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMan
AbpTickerQBackgroundWorkersProvider.BackgroundWorkers.Remove(functionName); AbpTickerQBackgroundWorkersProvider.BackgroundWorkers.Remove(functionName);
HandlerRegistry.Unregister(workerName); HandlerRegistry.Unregister(workerName);
// Note: ICronTickerManager<T> does not provide a remove API. // ICronTickerManager<T> does not provide a remove API, so the persisted
// The handler is unregistered above, so any persisted cron entry will // cron entry will remain in storage. The handler is unregistered above,
// find a null handler and skip execution silently. // so the entry will find a null handler and skip execution silently.
Logger.LogWarning(
"Dynamic worker '{WorkerName}' removed from memory, but the persisted TickerQ cron entry may remain in storage.",
workerName);
return Task.FromResult(true); return Task.FromResult(true);
} }

Loading…
Cancel
Save