Browse Source

Enable nullable annotations for Volo.Abp.BackgroundJobsRabbitMQ

pull/17109/head
liangshiwei 3 years ago
parent
commit
389e51d3fe
  1. 2
      framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo.Abp.BackgroundJobs.RabbitMQ.csproj
  2. 2
      framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueue.cs
  3. 16
      framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs
  4. 4
      framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueConfiguration.cs
  5. 2
      framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs

2
framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo.Abp.BackgroundJobs.RabbitMQ.csproj

@ -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>

2
framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueue.cs

@ -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

16
framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs

@ -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; }
@ -71,7 +71,7 @@ public class JobQueue<TArgs> : IJobQueue<TArgs>
);
}
public virtual async Task<string> EnqueueAsync(
public virtual async Task<string?> EnqueueAsync(
TArgs args,
BackgroundJobPriority priority = BackgroundJobPriority.Normal,
TimeSpan? delay = null)
@ -176,7 +176,7 @@ public class JobQueue<TArgs> : IJobQueue<TArgs>
basicProperties.Expiration = delay.Value.TotalMilliseconds.ToString();
}
ChannelAccessor.Channel.BasicPublish(
ChannelAccessor!.Channel.BasicPublish(
exchange: "",
routingKey: routingKey,
basicProperties: basicProperties,
@ -188,7 +188,7 @@ public class JobQueue<TArgs> : IJobQueue<TArgs>
protected virtual IBasicProperties CreateBasicPropertiesToPublish()
{
var properties = ChannelAccessor.Channel.CreateBasicProperties();
var properties = ChannelAccessor!.Channel.CreateBasicProperties();
properties.Persistent = true;
return properties;
}
@ -206,17 +206,17 @@ public class JobQueue<TArgs> : IJobQueue<TArgs>
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);
}
}
}

4
framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueConfiguration.cs

@ -9,7 +9,7 @@ public class JobQueueConfiguration : QueueDeclareConfiguration
{
public Type JobArgsType { get; }
public string ConnectionName { get; set; }
public string? ConnectionName { get; set; }
public string DelayedQueueName { get; set; }
@ -17,7 +17,7 @@ public class JobQueueConfiguration : QueueDeclareConfiguration
Type jobArgsType,
string queueName,
string delayedQueueName,
string connectionName = null,
string? connectionName = null,
bool durable = true,
bool exclusive = false,
bool autoDelete = false,

2
framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs

@ -20,6 +20,6 @@ public class RabbitMqBackgroundJobManager : IBackgroundJobManager, ITransientDep
TimeSpan? delay = null)
{
var jobQueue = await _jobQueueManager.GetAsync<TArgs>();
return await jobQueue.EnqueueAsync(args, priority, delay);
return (await jobQueue.EnqueueAsync(args, priority, delay))!;
}
}

Loading…
Cancel
Save