Browse Source

增加后台清理过期通知任务;修复拼写错误;

pull/9/head
cKey 6 years ago
parent
commit
b9835cd04b
  1. 14
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs
  2. 21
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs
  3. 16
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs
  4. 41
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationCleanupBackgroundWorker.cs
  5. 8
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj
  6. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContractsModule.cs
  7. 8
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj
  8. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationModule.cs
  9. 6
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/Notification.cs
  10. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs
  11. 7
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs
  12. 23
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN.Abp.MessageService.HttpApi.Client.csproj
  13. 20
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiClientModule.cs
  14. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs
  15. 14
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs
  16. 2
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs

14
aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs

@ -2,6 +2,7 @@
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LINGYUN.Abp.Notifications.WeChat.WeApp namespace LINGYUN.Abp.Notifications.WeChat.WeApp
@ -12,7 +13,8 @@ namespace LINGYUN.Abp.Notifications.WeChat.WeApp
public class WeChatWeAppNotificationPublishProvider : NotificationPublishProvider public class WeChatWeAppNotificationPublishProvider : NotificationPublishProvider
{ {
public override string Name => "WeChat.WeApp"; public override string Name => "WeChat.WeApp";
private INotificationSubscriptionManager _notificationSubscriptionManager;
protected INotificationSubscriptionManager NotificationSubscriptionManager => LazyGetRequiredService(ref _notificationSubscriptionManager);
protected IWeChatWeAppNotificationSender NotificationSender { get; } protected IWeChatWeAppNotificationSender NotificationSender { get; }
protected AbpWeChatWeAppNotificationOptions Options { get; } protected AbpWeChatWeAppNotificationOptions Options { get; }
public WeChatWeAppNotificationPublishProvider( public WeChatWeAppNotificationPublishProvider(
@ -32,6 +34,16 @@ namespace LINGYUN.Abp.Notifications.WeChat.WeApp
// step2 调用微信消息推送接口 // step2 调用微信消息推送接口
// 微信不支持推送到所有用户,需要获取订阅列表再发送
// 在小程序里用户订阅消息后通过 api/subscribes/subscribe 接口订阅对应模板消息
if (identifiers == null)
{
var userSubscriptions = await NotificationSubscriptionManager
.GetSubscriptionsAsync(notification.TenantId, notification.Name);
identifiers = userSubscriptions
.Select(us => new UserIdentifier(us.UserId, us.UserName));
}
foreach (var identifier in identifiers) foreach (var identifier in identifiers)
{ {
await SendWeChatTemplateMessagAsync(notification, identifier); await SendWeChatTemplateMessagAsync(notification, identifier);

21
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs

@ -0,0 +1,21 @@
namespace LINGYUN.Abp.Notifications
{
public class AbpNotificationCleanupOptions
{
/// <summary>
/// 是否启用清理任务
/// 默认:启用
/// </summary>
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 清理时间间隔
/// 默认:300000ms
/// </summary>
public int CleanupPeriod { get; set; } = 300000;
/// <summary>
/// 清理批次
/// 默认: 200
/// </summary>
public int CleanupBatchSize { get; set; } = 200;
}
}

16
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs

@ -1,9 +1,11 @@
using LINGYUN.Abp.Notifications.Internal; using LINGYUN.Abp.Notifications.Internal;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.BackgroundJobs; using Volo.Abp.BackgroundJobs;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Json; using Volo.Abp.Json;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -25,6 +27,20 @@ namespace LINGYUN.Abp.Notifications
context.Services.AddTransient<INotificationDispatcher, DefaultNotificationDispatcher>(); context.Services.AddTransient<INotificationDispatcher, DefaultNotificationDispatcher>();
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpNotificationCleanupOptions>>().Value;
if (options.IsEnabled)
{
context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.Add(
context.ServiceProvider
.GetRequiredService<NotificationCleanupBackgroundWorker>()
);
}
}
private static void AutoAddDefinitionProviders(IServiceCollection services) private static void AutoAddDefinitionProviders(IServiceCollection services)
{ {
var definitionProviders = new List<Type>(); var definitionProviders = new List<Type>();

41
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationCleanupBackgroundWorker.cs

@ -0,0 +1,41 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Threading;
namespace LINGYUN.Abp.Notifications.Internal
{
internal class NotificationCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{
protected AbpNotificationCleanupOptions Options { get; }
public NotificationCleanupBackgroundWorker(
AbpTimer timer,
IServiceScopeFactory serviceScopeFactory,
IOptions<AbpNotificationCleanupOptions> options)
: base(timer, serviceScopeFactory)
{
Options = options.Value;
timer.Period = Options.CleanupPeriod;
}
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
try
{
var store = workerContext.ServiceProvider.GetRequiredService<INotificationStore>();
Logger.LogDebug("Before cleanup exprition jobs...");
await store.DeleteNotificationAsync(Options.CleanupBatchSize);
Logger.LogDebug("Exprition jobs cleanup job was successful...");
}
catch (Exception ex)
{
Logger.LogWarning("Exprition jobs cleanup job was failed...");
Logger.LogWarning("Error:{0}", ex.Message);
}
}
}
}

8
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj

@ -3,8 +3,16 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace /> <RootNamespace />
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.9.0</Version>
<Authors>LINGYUN</Authors>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>D:\LocalNuget</OutputPath>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Volo.Abp.Ddd.Application.Contracts" Version="2.9.0" /> <PackageReference Include="Volo.Abp.Ddd.Application.Contracts" Version="2.9.0" />
<PackageReference Include="Volo.Abp.Authorization" Version="2.9.0" /> <PackageReference Include="Volo.Abp.Authorization" Version="2.9.0" />

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContrantsModule.cs → aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContractsModule.cs

@ -6,13 +6,13 @@ using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.MessageService namespace LINGYUN.Abp.MessageService
{ {
[DependsOn(typeof(AbpMessageServiceDomainSharedModule))] [DependsOn(typeof(AbpMessageServiceDomainSharedModule))]
public class AbpMessageServiceApplicationContrantsModule : AbpModule public class AbpMessageServiceApplicationContractsModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
Configure<AbpVirtualFileSystemOptions>(options => Configure<AbpVirtualFileSystemOptions>(options =>
{ {
options.FileSets.AddEmbedded<AbpMessageServiceApplicationContrantsModule>(); options.FileSets.AddEmbedded<AbpMessageServiceApplicationContractsModule>();
}); });
Configure<AbpLocalizationOptions>(options => Configure<AbpLocalizationOptions>(options =>

8
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj

@ -3,8 +3,16 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace /> <RootNamespace />
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.9.0</Version>
<Authors>LINGYUN</Authors>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>D:\LocalNuget</OutputPath>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Volo.Abp.Ddd.Application" Version="2.9.0" /> <PackageReference Include="Volo.Abp.Ddd.Application" Version="2.9.0" />
</ItemGroup> </ItemGroup>

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/AbpMessageServiceApplicationModule.cs → aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationModule.cs

@ -3,7 +3,7 @@
namespace LINGYUN.Abp.MessageService namespace LINGYUN.Abp.MessageService
{ {
[DependsOn( [DependsOn(
typeof(AbpMessageServiceApplicationContrantsModule), typeof(AbpMessageServiceApplicationContractsModule),
typeof(AbpMessageServiceDomainModule))] typeof(AbpMessageServiceDomainModule))]
public class AbpMessageServiceApplicationModule : AbpModule public class AbpMessageServiceApplicationModule : AbpModule
{ {

6
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/Notification.cs

@ -19,6 +19,12 @@ namespace LINGYUN.Abp.MessageService.Notifications
public virtual DateTime? ExpirationTime { get; set; } public virtual DateTime? ExpirationTime { get; set; }
public virtual DateTime CreationTime { get; set; } public virtual DateTime CreationTime { get; set; }
protected Notification(){} protected Notification(){}
public Notification(long id)
{
Id = id;
}
public Notification(long id, string category, string name, string dataType, string data, NotificationSeverity severity = NotificationSeverity.Info) public Notification(long id, string category, string name, string dataType, string data, NotificationSeverity severity = NotificationSeverity.Info)
{ {
NotificationId = id; NotificationId = id;

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs

@ -1,6 +1,8 @@
using LINGYUN.Abp.IM.Group; using LINGYUN.Abp.IM.Group;
using LINGYUN.Abp.MessageService.EntityFrameworkCore; using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

7
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs

@ -20,12 +20,15 @@ namespace LINGYUN.Abp.MessageService.Notifications
public async Task DeleteExpritionAsync(int batchCount) public async Task DeleteExpritionAsync(int batchCount)
{ {
var notifications = await DbSet var batchDeleteNoticeWithIds = await DbSet
.Where(x => x.ExpirationTime <= DateTime.Now) .Where(x => x.ExpirationTime <= DateTime.Now)
.Take(batchCount) .Take(batchCount)
.Select(x => new Notification(x.Id))
.AsNoTracking()
.ToArrayAsync(); .ToArrayAsync();
DbSet.RemoveRange(notifications); DbSet.AttachRange(batchDeleteNoticeWithIds);
DbSet.RemoveRange(batchDeleteNoticeWithIds);
} }
public async Task<Notification> GetByIdAsync(long notificationId) public async Task<Notification> GetByIdAsync(long notificationId)

23
aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN.Abp.MessageService.HttpApi.Client.csproj

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace />
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.9.0</Version>
<Authors>LINGYUN</Authors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>D:\LocalNuget</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Http.Client" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.MessageService.Application.Contracts\LINGYUN.Abp.MessageService.Application.Contracts.csproj" />
</ItemGroup>
</Project>

20
aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi.Client/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiClientModule.cs

@ -0,0 +1,20 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Http.Client;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.MessageService
{
[DependsOn(
typeof(AbpMessageServiceApplicationContractsModule),
typeof(AbpHttpClientModule))]
public class AbpMessageServiceHttpApiClientModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddHttpClientProxies(
typeof(AbpMessageServiceApplicationContractsModule).Assembly,
AbpMessageServiceConsts.RemoteServiceName
);
}
}
}

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs

@ -5,7 +5,7 @@ using Volo.Abp.Modularity;
namespace LINGYUN.Abp.MessageService namespace LINGYUN.Abp.MessageService
{ {
[DependsOn( [DependsOn(
typeof(AbpMessageServiceApplicationContrantsModule), typeof(AbpMessageServiceApplicationContractsModule),
typeof(AbpAspNetCoreMvcModule) typeof(AbpAspNetCoreMvcModule)
)] )]
public class AbpMessageServiceHttpApiModule : AbpModule public class AbpMessageServiceHttpApiModule : AbpModule

14
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs

@ -156,13 +156,13 @@ namespace LINGYUN.Abp.MessageService
} }
} }
public override void OnPostApplicationInitialization(ApplicationInitializationContext context) //public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
{ //{
var backgroundJobManager = context.ServiceProvider.GetRequiredService<IBackgroundJobManager>(); // var backgroundJobManager = context.ServiceProvider.GetRequiredService<IBackgroundJobManager>();
// 五分钟执行一次的定时任务 // // 五分钟执行一次的定时任务
AsyncHelper.RunSync(async () => await // AsyncHelper.RunSync(async () => await
backgroundJobManager.EnqueueAsync(CronGenerator.Minute(5), new NotificationCleanupExpritionJobArgs(200))); // backgroundJobManager.EnqueueAsync(CronGenerator.Minute(5), new NotificationCleanupExpritionJobArgs(200)));
} //}
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)
{ {

2
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs

@ -54,7 +54,7 @@ namespace LINGYUN.Platform
typeof(AbpPermissionManagementDomainIdentityModule), typeof(AbpPermissionManagementDomainIdentityModule),
typeof(AbpPermissionManagementDomainIdentityServerModule), typeof(AbpPermissionManagementDomainIdentityServerModule),
typeof(ApiGatewayApplicationContractsModule), typeof(ApiGatewayApplicationContractsModule),
typeof(AbpMessageServiceApplicationContrantsModule), typeof(AbpMessageServiceApplicationContractsModule),
typeof(AbpIdentityHttpApiModule), typeof(AbpIdentityHttpApiModule),
typeof(AbpIdentityApplicationModule), typeof(AbpIdentityApplicationModule),
typeof(Abp.Account.AbpAccountApplicationModule), typeof(Abp.Account.AbpAccountApplicationModule),

Loading…
Cancel
Save