Enable nullable annotations for Volo.Abp.BackgroundWorkers.Hangfire

pull/17109/head
liangshiwei 2 years ago
parent 5d3610f9a5
commit 4ffbf69a67

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.BackgroundWorkers.Hangfire</AssemblyName>
<PackageId>Volo.Abp.BackgroundWorkers.Hangfire</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

@ -38,7 +38,7 @@ public class AbpBackgroundWorkersHangfireModule : AbpModule
AsyncHelper.RunSync(() => OnPreApplicationInitializationAsync(context));
}
private BackgroundJobServer CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider)
private BackgroundJobServer? CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider)
{
serviceProvider.GetRequiredService<JobStorage>();
return null;

@ -6,11 +6,11 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire;
public abstract class HangfireBackgroundWorkerBase : BackgroundWorkerBase, IHangfireBackgroundWorker
{
public string RecurringJobId { get; set; }
public string? RecurringJobId { get; set; }
public string CronExpression { get; set; }
public string CronExpression { get; set; } = default!;
public TimeZoneInfo TimeZone { get; set; }
public TimeZoneInfo? TimeZone { get; set; }
public string Queue { get; set; }

@ -14,7 +14,7 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire;
[Dependency(ReplaceServices = true)]
public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISingletonDependency
{
protected AbpHangfireBackgroundJobServer BackgroundJobServer { get; set; }
protected AbpHangfireBackgroundJobServer BackgroundJobServer { get; set; } = default!;
protected IServiceProvider ServiceProvider { get; }
public HangfireBackgroundWorkerManager(IServiceProvider serviceProvider)
@ -57,7 +57,7 @@ public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISinglet
var timer = worker.GetType()
.GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker);
var period = worker is AsyncPeriodicBackgroundWorkerBase ? ((AbpAsyncTimer)timer)?.Period : ((AbpTimer)timer)?.Period;
var period = worker is AsyncPeriodicBackgroundWorkerBase ? ((AbpAsyncTimer?)timer)?.Period : ((AbpTimer?)timer)?.Period;
if (period == null)
{
@ -65,7 +65,7 @@ public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISinglet
}
var adapterType = typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(ProxyHelper.GetUnProxiedType(worker));
var workerAdapter = Activator.CreateInstance(adapterType) as IHangfireBackgroundWorker;
var workerAdapter = (Activator.CreateInstance(adapterType) as IHangfireBackgroundWorker)!;
RecurringJob.AddOrUpdate(() => workerAdapter.DoWorkAsync(cancellationToken), GetCron(period.Value), workerAdapter.TimeZone, workerAdapter.Queue);

@ -14,8 +14,8 @@ public class HangfirePeriodicBackgroundWorkerAdapter<TWorker> : HangfireBackgrou
public HangfirePeriodicBackgroundWorkerAdapter()
{
_doWorkAsyncMethod =
typeof(TWorker).GetMethod("DoWorkAsync", BindingFlags.Instance | BindingFlags.NonPublic);
_doWorkMethod = typeof(TWorker).GetMethod("DoWork", BindingFlags.Instance | BindingFlags.NonPublic);
typeof(TWorker).GetMethod("DoWorkAsync", BindingFlags.Instance | BindingFlags.NonPublic)!;
_doWorkMethod = typeof(TWorker).GetMethod("DoWork", BindingFlags.Instance | BindingFlags.NonPublic)!;
}
public async override Task DoWorkAsync(CancellationToken cancellationToken = default)
@ -26,7 +26,7 @@ public class HangfirePeriodicBackgroundWorkerAdapter<TWorker> : HangfireBackgrou
switch (worker)
{
case AsyncPeriodicBackgroundWorkerBase asyncPeriodicBackgroundWorker:
await (Task)_doWorkAsyncMethod.Invoke(asyncPeriodicBackgroundWorker, new object[] { workerContext });
await (Task)(_doWorkAsyncMethod.Invoke(asyncPeriodicBackgroundWorker, new object[] { workerContext })!);
break;
case PeriodicBackgroundWorkerBase periodicBackgroundWorker:
_doWorkMethod.Invoke(periodicBackgroundWorker, new object[] { workerContext });

@ -6,11 +6,11 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire;
public interface IHangfireBackgroundWorker : IBackgroundWorker
{
string RecurringJobId { get; set; }
string? RecurringJobId { get; set; }
string CronExpression { get; set; }
TimeZoneInfo TimeZone { get; set; }
TimeZoneInfo? TimeZone { get; set; }
string Queue { get; set; }

Loading…
Cancel
Save