Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group8 Enable nullable annotations #17109

Merged
merged 14 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.AzureServiceBus</AssemblyName>
<PackageId>Volo.Abp.AzureServiceBus</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class AzureServiceBusMessageConsumer : IAzureServiceBusMessageConsumer, I
private readonly IExceptionNotifier _exceptionNotifier;
private readonly IProcessorPool _processorPool;
private readonly ConcurrentBag<Func<ServiceBusReceivedMessage, Task>> _callbacks;
private string _connectionName;
private string _subscriptionName;
private string _topicName;
private string _connectionName = default!;
private string _subscriptionName = default!;
private string _topicName = default!;

public AzureServiceBusMessageConsumer(
IExceptionNotifier exceptionNotifier,
Expand All @@ -37,7 +37,7 @@ public AzureServiceBusMessageConsumer(
public virtual void Initialize(
[NotNull] string topicName,
[NotNull] string subscriptionName,
string connectionName)
string? connectionName)
{
Check.NotNull(topicName, nameof(topicName));
Check.NotNull(subscriptionName, nameof(subscriptionName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Volo.Abp.AzureServiceBus;

public class ClientConfig
{
public string ConnectionString { get; set; }
public string ConnectionString { get; set; } = default!;

public ServiceBusAdministrationClientOptions Admin { get; set; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.BackgroundJobs.Abstractions</AssemblyName>
<PackageId>Volo.Abp.BackgroundJobs.Abstractions</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public virtual async Task ExecuteAsync(JobExecutionContext context)
{
if (jobExecuteMethod.Name == nameof(IAsyncBackgroundJob<object>.ExecuteAsync))
{
await ((Task)jobExecuteMethod.Invoke(job, new[] { context.JobArgs }));
await ((Task)jobExecuteMethod.Invoke(job, new[] { context.JobArgs })!);
}
else
{
Expand All @@ -74,7 +74,7 @@ await context.ServiceProvider

throw new BackgroundJobExecutionException("A background job execution is failed. See inner exception for details.", ex)
{
JobType = context.JobType.AssemblyQualifiedName,
JobType = context.JobType.AssemblyQualifiedName!,
JobArgs = context.JobArgs
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Volo.Abp.BackgroundJobs;
[Serializable]
public class BackgroundJobExecutionException : AbpException
{
public string JobType { get; set; }
public string JobType { get; set; } = default!;

public object JobArgs { get; set; }
public object JobArgs { get; set; } = default!;

public BackgroundJobExecutionException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public static string GetName([NotNull] Type jobArgsType)
{
Check.NotNull(jobArgsType, nameof(jobArgsType));

return jobArgsType
.GetCustomAttributes(true)
.OfType<IBackgroundJobNameProvider>()
.FirstOrDefault()
?.Name
?? jobArgsType.FullName;
return (jobArgsType
.GetCustomAttributes(true)
.OfType<IBackgroundJobNameProvider>()
.FirstOrDefault()
?.Name
?? jobArgsType.FullName)!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.BackgroundJobs.HangFire</AssemblyName>
<PackageId>Volo.Abp.BackgroundJobs.HangFire</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void OnPreApplicationInitialization(ApplicationInitializationCon
}
}

private BackgroundJobServer CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider)
private BackgroundJobServer? CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider)
{
serviceProvider.GetRequiredService<JobStorage>();
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task ExecuteAsync(string queue, TArgs args, CancellationToken cance
using (var scope = ServiceScopeFactory.CreateScope())
{
var jobType = Options.GetJob(typeof(TArgs)).JobType;
var context = new JobExecutionContext(scope.ServiceProvider, jobType, args, cancellationToken: cancellationToken);
var context = new JobExecutionContext(scope.ServiceProvider, jobType, args!, cancellationToken: cancellationToken);
await JobExecuter.ExecuteAsync(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.BackgroundJobs.Quartz</AssemblyName>
<PackageId>Volo.Abp.BackgroundJobs.Quartz</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ private async Task DefaultRetryStrategy(int retryIndex, IJobExecutionContext exe
{
exception.RefireImmediately = true;

var retryCount = executionContext.JobDetail.JobDataMap.GetString(QuartzBackgroundJobManager.JobDataPrefix + nameof(RetryCount)).To<int>();
var retryCount = executionContext.JobDetail.JobDataMap.GetString(QuartzBackgroundJobManager.JobDataPrefix + nameof(RetryCount))!.To<int>();
if (retryIndex > retryCount)
{
exception.RefireImmediately = false;
exception.UnscheduleAllTriggers = true;
return;
}

var retryInterval = executionContext.JobDetail.JobDataMap.GetString(QuartzBackgroundJobManager.JobDataPrefix + nameof(RetryIntervalMillisecond)).To<int>();
var retryInterval = executionContext.JobDetail.JobDataMap.GetString(QuartzBackgroundJobManager.JobDataPrefix + nameof(RetryIntervalMillisecond))!.To<int>();
await Task.Delay(retryInterval);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public override void ConfigureServices(ServiceConfigurationContext context)

public override void OnPreApplicationInitialization(ApplicationInitializationContext context)
{
var options = context.ServiceProvider.GetService<IOptions<AbpBackgroundJobOptions>>().Value;
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpBackgroundJobOptions>>().Value;
if (!options.IsJobExecutionEnabled)
{
var quartzOptions = context.ServiceProvider.GetService<IOptions<AbpQuartzOptions>>().Value;
var quartzOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpQuartzOptions>>().Value;
quartzOptions.StartSchedulerFactory = scheduler => Task.CompletedTask;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Volo.Abp.BackgroundJobs.Quartz;

public static class QuartzBackgroundJobManageExtensions
{
public static async Task<string> EnqueueAsync<TArgs>(this IBackgroundJobManager backgroundJobManager,
public static async Task<string?> EnqueueAsync<TArgs>(this IBackgroundJobManager backgroundJobManager,
TArgs args, int retryCount, int retryIntervalMillisecond,
BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public virtual async Task<string> ReEnqueueAsync<TArgs>(TArgs args, int retryCou
{
var jobDataMap = new JobDataMap
{
{nameof(TArgs), JsonSerializer.Serialize(args)},
{nameof(TArgs), JsonSerializer.Serialize(args!)},
{JobDataPrefix+ nameof(Options.RetryCount), retryCount.ToString()},
{JobDataPrefix+ nameof(Options.RetryIntervalMillisecond), retryIntervalMillisecond.ToString()},
{JobDataPrefix+ RetryIndex, "0"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public async Task Execute(IJobExecutionContext context)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var args = JsonSerializer.Deserialize<TArgs>(context.JobDetail.JobDataMap.GetString(nameof(TArgs)));
var args = JsonSerializer.Deserialize<TArgs>(context.JobDetail.JobDataMap.GetString(nameof(TArgs))!);
var jobType = Options.GetJob(typeof(TArgs)).JobType;
var jobContext = new JobExecutionContext(scope.ServiceProvider, jobType, args, cancellationToken: context.CancellationToken);
var jobContext = new JobExecutionContext(scope.ServiceProvider, jobType, args!, cancellationToken: context.CancellationToken);
try
{
await JobExecuter.ExecuteAsync(jobContext);
Expand All @@ -49,7 +49,7 @@ public async Task Execute(IJobExecutionContext context)
{
var jobExecutionException = new JobExecutionException(exception);

var retryIndex = context.JobDetail.JobDataMap.GetString(QuartzBackgroundJobManager.JobDataPrefix + QuartzBackgroundJobManager.RetryIndex).To<int>();
var retryIndex = context.JobDetail.JobDataMap.GetString(QuartzBackgroundJobManager.JobDataPrefix + QuartzBackgroundJobManager.RetryIndex)!.To<int>();
retryIndex++;
context.JobDetail.JobDataMap.Put(QuartzBackgroundJobManager.JobDataPrefix + QuartzBackgroundJobManager.RetryIndex, retryIndex.ToString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.BackgroundJobs.RabbitMQ</AssemblyName>
<PackageId>Volo.Abp.BackgroundJobs.RabbitMQ</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ;

public interface IJobQueue<in TArgs> : IRunnable, IDisposable
{
Task<string> EnqueueAsync(
Task<string?> EnqueueAsync(
TArgs args,
BackgroundJobPriority priority = BackgroundJobPriority.Normal,
TimeSpan? delay = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class JobQueue<TArgs> : IJobQueue<TArgs>

protected BackgroundJobConfiguration JobConfiguration { get; }
protected JobQueueConfiguration QueueConfiguration { get; }
protected IChannelAccessor ChannelAccessor { get; private set; }
protected AsyncEventingBasicConsumer Consumer { get; private set; }
protected IChannelAccessor? ChannelAccessor { get; private set; }
protected AsyncEventingBasicConsumer? Consumer { get; private set; }

public ILogger<JobQueue<TArgs>> Logger { get; set; }

Expand Down Expand Up @@ -71,7 +71,7 @@ protected virtual JobQueueConfiguration GetOrCreateJobQueueConfiguration()
);
}

public virtual async Task<string> EnqueueAsync(
public virtual async Task<string?> EnqueueAsync(
TArgs args,
BackgroundJobPriority priority = BackgroundJobPriority.Normal,
TimeSpan? delay = null)
Expand Down Expand Up @@ -176,19 +176,19 @@ protected virtual Task PublishAsync(
basicProperties.Expiration = delay.Value.TotalMilliseconds.ToString();
}

ChannelAccessor.Channel.BasicPublish(
ChannelAccessor!.Channel.BasicPublish(
exchange: "",
routingKey: routingKey,
basicProperties: basicProperties,
body: Serializer.Serialize(args)
body: Serializer.Serialize(args!)
);

return Task.CompletedTask;
}

protected virtual IBasicProperties CreateBasicPropertiesToPublish()
{
var properties = ChannelAccessor.Channel.CreateBasicProperties();
var properties = ChannelAccessor!.Channel.CreateBasicProperties();
properties.Persistent = true;
return properties;
}
Expand All @@ -206,17 +206,17 @@ protected virtual async Task MessageReceived(object sender, BasicDeliverEventArg
try
{
await JobExecuter.ExecuteAsync(context);
ChannelAccessor.Channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
ChannelAccessor!.Channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
}
catch (BackgroundJobExecutionException)
{
//TODO: Reject like that?
ChannelAccessor.Channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: true);
ChannelAccessor!.Channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: true);
}
catch (Exception)
{
//TODO: Reject like that?
ChannelAccessor.Channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: false);
ChannelAccessor!.Channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class JobQueueConfiguration : QueueDeclareConfiguration
{
public Type JobArgsType { get; }

public string ConnectionName { get; set; }
public string? ConnectionName { get; set; }

public string DelayedQueueName { get; set; }

public JobQueueConfiguration(
Type jobArgsType,
string queueName,
string delayedQueueName,
string connectionName = null,
string? connectionName = null,
bool durable = true,
bool exclusive = false,
bool autoDelete = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public async Task<string> EnqueueAsync<TArgs>(
TimeSpan? delay = null)
{
var jobQueue = await _jobQueueManager.GetAsync<TArgs>();
return await jobQueue.EnqueueAsync(args, priority, delay);
return (await jobQueue.EnqueueAsync(args, priority, delay))!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.BackgroundJobs</AssemblyName>
<PackageId>Volo.Abp.BackgroundJobs</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class BackgroundJobInfo
/// <summary>
/// Name of the job.
/// </summary>
public virtual string JobName { get; set; }
public virtual string JobName { get; set; } = default!;

/// <summary>
/// Job arguments as serialized to string.
/// </summary>
public virtual string JobArgs { get; set; }
public virtual string JobArgs { get; set; } = default!;

/// <summary>
/// Try count of this job.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DefaultBackgroundJobManager(
public virtual async Task<string> EnqueueAsync<TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null)
{
var jobName = BackgroundJobNameAttribute.GetName<TArgs>();
var jobId = await EnqueueAsync(jobName, args, priority, delay);
var jobId = await EnqueueAsync(jobName, args!, priority, delay);
return jobId.ToString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public InMemoryBackgroundJobStore(IClock clock)

public virtual Task<BackgroundJobInfo> FindAsync(Guid jobId)
{
return Task.FromResult(_jobs.GetOrDefault(jobId));
return Task.FromResult(_jobs.GetOrDefault(jobId))!;
}

public virtual Task InsertAsync(BackgroundJobInfo jobInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override void OnPreApplicationInitialization(ApplicationInitializationCon
AsyncHelper.RunSync(() => OnPreApplicationInitializationAsync(context));
}

private BackgroundJobServer CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider)
private BackgroundJobServer? CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider)
{
serviceProvider.GetRequiredService<JobStorage>();
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Loading