27 changed files with 344 additions and 390 deletions
@ -0,0 +1,10 @@ |
|||
// Global using directives
|
|||
|
|||
global using Hangfire; |
|||
global using Hangfire.Common; |
|||
global using Hangfire.Dashboard; |
|||
global using Hangfire.States; |
|||
global using Hangfire.Storage; |
|||
global using Microsoft.Extensions.DependencyInjection; |
|||
global using Volo.Abp.DependencyInjection; |
|||
global using Volo.Abp.Users; |
|||
@ -0,0 +1,12 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net9.0</TargetFramework> |
|||
<ImplicitUsings>enable</ImplicitUsings> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.BackgroundJobs.HangFire" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,4 +1,4 @@ |
|||
namespace Lion.AbpPro.Extensions.Hangfire; |
|||
namespace Lion.AbpPro.Hangfire; |
|||
|
|||
public class AutoDeleteAfterSuccessAttribute : JobFilterAttribute, IApplyStateFilter |
|||
{ |
|||
@ -0,0 +1,77 @@ |
|||
namespace Lion.AbpPro.Hangfire; |
|||
|
|||
/// <summary>
|
|||
/// Cron类型
|
|||
/// </summary>
|
|||
public static class CronType |
|||
{ |
|||
/// <summary>
|
|||
/// 周期性为分钟的任务
|
|||
/// </summary>
|
|||
/// <param name="interval">执行周期的间隔,默认为每分钟一次</param>
|
|||
/// <returns></returns>
|
|||
public static string Minute(int interval = 1) |
|||
{ |
|||
return "1 0/" + interval.ToString() + " * * * ? "; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为小时的任务
|
|||
/// </summary>
|
|||
/// <param name="minute">第几分钟开始,默认为第一分钟</param>
|
|||
/// <param name="interval">执行周期的间隔,默认为每小时一次</param>
|
|||
/// <returns></returns>
|
|||
public static string Hour(int minute = 1, int interval = 1) |
|||
{ |
|||
return "1 " + minute + " 0/" + interval.ToString() + " * * ? "; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为天的任务
|
|||
/// </summary>
|
|||
/// <param name="hour">第几小时开始,默认从1点开始</param>
|
|||
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
|
|||
/// <param name="interval">执行周期的间隔,默认为每天一次</param>
|
|||
/// <returns></returns>
|
|||
public static string Day(int hour = 1, int minute = 1, int interval = 1) |
|||
{ |
|||
return "1 " + minute.ToString() + " " + hour.ToString() + " 1/" + interval.ToString() + " * ? "; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为周的任务
|
|||
/// </summary>
|
|||
/// <param name="dayOfWeek">星期几开始,默认从星期一点开始</param>
|
|||
/// <param name="hour">第几小时开始,默认从1点开始</param>
|
|||
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
|
|||
/// <returns></returns>
|
|||
public static string Week(DayOfWeek dayOfWeek = DayOfWeek.Monday, int hour = 1, int minute = 1) |
|||
{ |
|||
return Cron.Weekly(dayOfWeek, hour, minute); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为月的任务
|
|||
/// </summary>
|
|||
/// <param name="day">几号开始,默认从一号开始</param>
|
|||
/// <param name="hour">第几小时开始,默认从1点开始</param>
|
|||
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
|
|||
/// <returns></returns>
|
|||
public static string Month(int day = 1, int hour = 1, int minute = 1) |
|||
{ |
|||
return Cron.Monthly(day, hour, minute); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为年的任务
|
|||
/// </summary>
|
|||
/// <param name="month">几月开始,默认从一月开始</param>
|
|||
/// <param name="day">几号开始,默认从一号开始</param>
|
|||
/// <param name="hour">第几小时开始,默认从1点开始</param>
|
|||
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
|
|||
/// <returns></returns>
|
|||
public static string Year(int month = 1, int day = 1, int hour = 1, int minute = 1) |
|||
{ |
|||
return Cron.Yearly(month, day, hour, minute); |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Lion.AbpPro.Hangfire; |
|||
|
|||
public class CustomHangfireAuthorizeFilter : IDashboardAuthorizationFilter |
|||
{ |
|||
public bool Authorize(DashboardContext context) |
|||
{ |
|||
var currentUser = context.GetHttpContext().RequestServices.GetRequiredService<ICurrentUser>(); |
|||
return currentUser.IsAuthenticated; |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Lion.AbpPro.Hangfire; |
|||
|
|||
public interface IRecurringJob : ITransientDependency |
|||
{ |
|||
/// <summary>
|
|||
/// 执行任务
|
|||
/// </summary>
|
|||
Task ExecuteAsync(); |
|||
} |
|||
@ -1,40 +1,39 @@ |
|||
namespace Lion.AbpPro |
|||
namespace Lion.AbpPro; |
|||
|
|||
public static class AbpProHttpApiHostConst |
|||
{ |
|||
public static class AbpProHttpApiHostConst |
|||
{ |
|||
/// <summary>
|
|||
/// 跨域策略名
|
|||
/// </summary>
|
|||
public const string DefaultCorsPolicyName = "Default"; |
|||
/// <summary>
|
|||
/// 跨域策略名
|
|||
/// </summary>
|
|||
public const string DefaultCorsPolicyName = "Default"; |
|||
|
|||
/// <summary>
|
|||
/// Cookies名称
|
|||
/// </summary>
|
|||
public const string DefaultCookieName = "Lion.AbpPro.Http.Api"; |
|||
/// <summary>
|
|||
/// Cookies名称
|
|||
/// </summary>
|
|||
public const string DefaultCookieName = "Lion.AbpPro.Http.Api"; |
|||
|
|||
/// <summary>
|
|||
/// SwaggerUi 端点
|
|||
/// </summary>
|
|||
public const string SwaggerUiEndPoint = "/swagger"; |
|||
/// <summary>
|
|||
/// SwaggerUi 端点
|
|||
/// </summary>
|
|||
public const string SwaggerUiEndPoint = "/swagger"; |
|||
|
|||
/// <summary>
|
|||
/// Hangfire 端点
|
|||
/// </summary>
|
|||
public const string HangfireDashboardEndPoint = "/hangfire"; |
|||
/// <summary>
|
|||
/// Hangfire 端点
|
|||
/// </summary>
|
|||
public const string HangfireDashboardEndPoint = "/hangfire"; |
|||
|
|||
/// <summary>
|
|||
/// CAP 端点
|
|||
/// </summary>
|
|||
public const string CapDashboardEndPoint = "/cap"; |
|||
/// <summary>
|
|||
/// CAP 端点
|
|||
/// </summary>
|
|||
public const string CapDashboardEndPoint = "/cap"; |
|||
|
|||
|
|||
public const string MoreEndPoint = "https://doc.cncore.club/"; |
|||
public const string MoreEndPoint = "https://doc.cncore.club/"; |
|||
|
|||
|
|||
/// <summary>
|
|||
/// HMiniprofiler端点
|
|||
/// </summary>
|
|||
public const string MiniprofilerEndPoint = "/profiler/results-index"; |
|||
/// <summary>
|
|||
/// HMiniprofiler端点
|
|||
/// </summary>
|
|||
public const string MiniprofilerEndPoint = "/profiler/results-index"; |
|||
|
|||
} |
|||
} |
|||
@ -1,143 +1,75 @@ |
|||
namespace Lion.AbpPro |
|||
namespace Lion.AbpPro; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpProHttpApiModule), |
|||
typeof(AbpProAspNetCoreModule), |
|||
typeof(AbpAspNetCoreMvcUiMultiTenancyModule), |
|||
typeof(AbpProEntityFrameworkCoreModule), |
|||
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), |
|||
typeof(AbpAspNetCoreSerilogModule), |
|||
typeof(AbpAccountWebModule), |
|||
typeof(AbpProApplicationModule), |
|||
// typeof(AbpProCapModule),
|
|||
// typeof(AbpProCapEntityFrameworkCoreModule),
|
|||
typeof(AbpAspNetCoreMvcUiBasicThemeModule), |
|||
typeof(AbpCachingStackExchangeRedisModule), |
|||
typeof(AbpDistributedLockingModule), |
|||
typeof(AbpBlobStoringFileSystemModule), |
|||
typeof(AbpProStarterModule), |
|||
typeof(AbpSwashbuckleModule) |
|||
//typeof(AbpBackgroundJobsHangfireModule)
|
|||
)] |
|||
public partial class AbpProHttpApiHostModule : AbpModule |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpProHttpApiModule), |
|||
typeof(AbpProAspNetCoreModule), |
|||
typeof(AbpAspNetCoreMvcUiMultiTenancyModule), |
|||
typeof(AbpProEntityFrameworkCoreModule), |
|||
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), |
|||
typeof(AbpAspNetCoreSerilogModule), |
|||
typeof(AbpAccountWebModule), |
|||
typeof(AbpProApplicationModule), |
|||
// typeof(AbpProCapModule),
|
|||
// typeof(AbpProCapEntityFrameworkCoreModule),
|
|||
typeof(AbpAspNetCoreMvcUiBasicThemeModule), |
|||
typeof(AbpCachingStackExchangeRedisModule), |
|||
typeof(AbpDistributedLockingModule), |
|||
typeof(AbpBlobStoringFileSystemModule), |
|||
typeof(AbpProStarterModule) |
|||
//typeof(AbpBackgroundJobsHangfireModule)
|
|||
)] |
|||
public partial class AbpProHttpApiHostModule : AbpModule |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
public override void OnPostApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
// 应用程序初始化的时候注册hangfire
|
|||
//context.CreateRecurringJob();
|
|||
base.OnPostApplicationInitialization(context); |
|||
} |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services |
|||
context.Services |
|||
|
|||
.AddAbpProAuditLog() |
|||
.AddAbpProAuthentication() |
|||
.AddAbpProMultiTenancy() |
|||
.AddAbpProRedis() |
|||
.AddAbpProRedisDistributedLocking() |
|||
.AddAbpProMiniProfiler() |
|||
.AddAbpProCors() |
|||
.AddAbpProAntiForgery() |
|||
.AddAbpProIdentity() |
|||
.AddAbpProBlobStorage() |
|||
.AddAbpProSignalR() |
|||
.AddAbpProHealthChecks() |
|||
.AddAbpProTenantResolvers() |
|||
.AddAbpProLocalization() |
|||
.AddAbpProExceptions() |
|||
.AddAbpProSwagger("AbpPro"); |
|||
|
|||
|
|||
// //ConfigureCache(context);
|
|||
// context.Services.AddAbpProRedis();
|
|||
//
|
|||
// //ConfigurationDistributedLocking(context);
|
|||
// context.Services.AddAbpProRedisDistributedLocking();
|
|||
//
|
|||
//
|
|||
// //ConfigureSwaggerServices(context);
|
|||
// context.Services.AddAbpProSwagger("AbpPro");
|
|||
//
|
|||
// //ConfigureJwtAuthentication(context, configuration);
|
|||
// context.Services.AddAbpProAuthentication();
|
|||
//
|
|||
// //ConfigureHangfire(context);
|
|||
//
|
|||
// //ConfigureMiniProfiler(context);
|
|||
// context.Services.AddAbpProMiniProfiler();
|
|||
//
|
|||
// //ConfigureIdentity(context);
|
|||
// context.Services.AddAbpProIdentity();
|
|||
//
|
|||
// //ConfigureCap(context);
|
|||
//
|
|||
// //ConfigureAuditLog(context);
|
|||
// context.Services.AddAbpProAuditLog();
|
|||
//
|
|||
// //ConfigurationSignalR(context);
|
|||
// context.Services.AddAbpProSignalR();
|
|||
//
|
|||
// //ConfigurationMultiTenancy();
|
|||
// context.Services.AddAbpProMultiTenancy();
|
|||
//
|
|||
// //ConfigureBlobStorage();
|
|||
// context.Services.AddAbpProBlobStorage();
|
|||
} |
|||
.AddAbpProAuditLog() |
|||
.AddAbpProAuthentication() |
|||
.AddAbpProMultiTenancy() |
|||
.AddAbpProRedis() |
|||
.AddAbpProRedisDistributedLocking() |
|||
.AddAbpProMiniProfiler() |
|||
.AddAbpProCors() |
|||
.AddAbpProAntiForgery() |
|||
.AddAbpProIdentity() |
|||
.AddAbpProBlobStorage() |
|||
.AddAbpProSignalR() |
|||
.AddAbpProHealthChecks() |
|||
.AddAbpProTenantResolvers() |
|||
.AddAbpProLocalization() |
|||
.AddAbpProExceptions() |
|||
.AddAbpProSwagger("AbpPro"); |
|||
} |
|||
|
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
var app = context.GetApplicationBuilder(); |
|||
app.UseAbpProRequestLocalization(); |
|||
app.UseCorrelationId(); |
|||
app.MapAbpStaticAssets(); |
|||
app.UseAbpProMiniProfiler(); |
|||
app.UseRouting(); |
|||
app.UseAbpProCors(); |
|||
app.UseAuthentication(); |
|||
app.UseAbpProMultiTenancy(); |
|||
app.UseAuthorization(); |
|||
app.UseAbpProSwaggerUI("/swagger/AbpPro/swagger.json","AbpPro"); |
|||
app.UseAbpProAuditing(); |
|||
app.UseAbpSerilogEnrichers(); |
|||
app.UseUnitOfWork(); |
|||
app.UseConfiguredEndpoints(endpoints => |
|||
{ |
|||
var app = context.GetApplicationBuilder(); |
|||
//var configuration = context.GetConfiguration();
|
|||
app.UseAbpProRequestLocalization(); |
|||
app.UseCorrelationId(); |
|||
app.MapAbpStaticAssets(); |
|||
// if (configuration.GetValue("MiniProfiler:Enabled", false))
|
|||
// {
|
|||
// app.UseMiniProfiler();
|
|||
// }
|
|||
|
|||
app.UseAbpProMiniProfiler(); |
|||
app.UseRouting(); |
|||
//app.UseCors(AbpProHttpApiHostConst.DefaultCorsPolicyName);
|
|||
app.UseAbpProCors(); |
|||
app.UseAuthentication(); |
|||
|
|||
// if (MultiTenancyConsts.IsEnabled)
|
|||
// {
|
|||
// app.UseMultiTenancy();
|
|||
// }
|
|||
|
|||
app.UseAbpProMultiTenancy(); |
|||
|
|||
app.UseAuthorization(); |
|||
// app.UseSwagger();
|
|||
// app.UseAbpSwaggerUI(options =>
|
|||
endpoints.MapHealthChecks("/health"); |
|||
|
|||
// endpoints.MapHangfireDashboard("/hangfire", new DashboardOptions()
|
|||
// {
|
|||
// options.SwaggerEndpoint("/swagger/AbpPro/swagger.json", "AbpPro API");
|
|||
// options.DocExpansion(DocExpansion.None);
|
|||
// options.DefaultModelsExpandDepth(-1);
|
|||
// Authorization = new[] { new CustomHangfireAuthorizeFilter() },
|
|||
// IgnoreAntiforgeryToken = true
|
|||
// });
|
|||
|
|||
app.UseAbpProSwaggerUI("/swagger/AbpPro/swagger.json","AbpPro"); |
|||
//app.UseAuditing();
|
|||
app.UseAbpProAuditing(); |
|||
|
|||
app.UseAbpSerilogEnrichers(); |
|||
app.UseUnitOfWork(); |
|||
app.UseConfiguredEndpoints(endpoints => |
|||
{ |
|||
endpoints.MapHealthChecks("/health"); |
|||
|
|||
// endpoints.MapHangfireDashboard("/hangfire", new DashboardOptions()
|
|||
// {
|
|||
// Authorization = new[] { new CustomHangfireAuthorizeFilter() },
|
|||
// IgnoreAntiforgeryToken = true
|
|||
// });
|
|||
|
|||
}); |
|||
|
|||
app.UseAbpProConsul(); |
|||
} |
|||
}); |
|||
app.UseAbpProConsul(); |
|||
} |
|||
} |
|||
@ -1,78 +0,0 @@ |
|||
namespace Lion.AbpPro.Extensions.Hangfire |
|||
{ |
|||
/// <summary>
|
|||
/// Cron类型
|
|||
/// </summary>
|
|||
public static class CronType |
|||
{ |
|||
/// <summary>
|
|||
/// 周期性为分钟的任务
|
|||
/// </summary>
|
|||
/// <param name="interval">执行周期的间隔,默认为每分钟一次</param>
|
|||
/// <returns></returns>
|
|||
public static string Minute(int interval = 1) |
|||
{ |
|||
return "1 0/" + interval.ToString() + " * * * ? "; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为小时的任务
|
|||
/// </summary>
|
|||
/// <param name="minute">第几分钟开始,默认为第一分钟</param>
|
|||
/// <param name="interval">执行周期的间隔,默认为每小时一次</param>
|
|||
/// <returns></returns>
|
|||
public static string Hour(int minute = 1, int interval = 1) |
|||
{ |
|||
return "1 " + minute + " 0/" + interval.ToString() + " * * ? "; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为天的任务
|
|||
/// </summary>
|
|||
/// <param name="hour">第几小时开始,默认从1点开始</param>
|
|||
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
|
|||
/// <param name="interval">执行周期的间隔,默认为每天一次</param>
|
|||
/// <returns></returns>
|
|||
public static string Day(int hour = 1, int minute = 1, int interval = 1) |
|||
{ |
|||
return "1 " + minute.ToString() + " " + hour.ToString() + " 1/" + interval.ToString() + " * ? "; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为周的任务
|
|||
/// </summary>
|
|||
/// <param name="dayOfWeek">星期几开始,默认从星期一点开始</param>
|
|||
/// <param name="hour">第几小时开始,默认从1点开始</param>
|
|||
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
|
|||
/// <returns></returns>
|
|||
public static string Week(DayOfWeek dayOfWeek = DayOfWeek.Monday, int hour = 1, int minute = 1) |
|||
{ |
|||
return Cron.Weekly(dayOfWeek, hour, minute); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为月的任务
|
|||
/// </summary>
|
|||
/// <param name="day">几号开始,默认从一号开始</param>
|
|||
/// <param name="hour">第几小时开始,默认从1点开始</param>
|
|||
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
|
|||
/// <returns></returns>
|
|||
public static string Month(int day = 1, int hour = 1, int minute = 1) |
|||
{ |
|||
return Cron.Monthly(day, hour, minute); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 周期性为年的任务
|
|||
/// </summary>
|
|||
/// <param name="month">几月开始,默认从一月开始</param>
|
|||
/// <param name="day">几号开始,默认从一号开始</param>
|
|||
/// <param name="hour">第几小时开始,默认从1点开始</param>
|
|||
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
|
|||
/// <returns></returns>
|
|||
public static string Year(int month = 1, int day = 1, int hour = 1, int minute = 1) |
|||
{ |
|||
return Cron.Yearly(month, day, hour, minute); |
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
namespace Lion.AbpPro.Extensions.Hangfire |
|||
{ |
|||
public class CustomHangfireAuthorizeFilter : IDashboardAuthorizationFilter |
|||
{ |
|||
public bool Authorize(DashboardContext context) |
|||
{ |
|||
var _currentUser = context.GetHttpContext().RequestServices.GetRequiredService<ICurrentUser>(); |
|||
return _currentUser.IsAuthenticated; |
|||
} |
|||
} |
|||
} |
|||
@ -1,15 +0,0 @@ |
|||
using Lion.AbpPro.Jobs; |
|||
|
|||
namespace Lion.AbpPro.Extensions.Hangfire |
|||
{ |
|||
public static class RecurringJobsExtensions |
|||
{ |
|||
public static void CreateRecurringJob(this ApplicationInitializationContext context) |
|||
{ |
|||
RecurringJob.AddOrUpdate<TestJob>("测试Job", e => e.ExecuteAsync(), CronType.Minute(1), new RecurringJobOptions() |
|||
{ |
|||
TimeZone = TimeZoneInfo.Local |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
namespace Lion.AbpPro.Jobs |
|||
{ |
|||
public interface IRecurringJob : ITransientDependency |
|||
{ |
|||
/// <summary>
|
|||
/// 执行任务
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task ExecuteAsync(); |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
namespace Lion.AbpPro.Jobs |
|||
{ |
|||
public class TestJob : IRecurringJob |
|||
{ |
|||
public Task ExecuteAsync() |
|||
{ |
|||
Console.WriteLine($"job 测试"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo9;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" |
|||
"Default": "Data Source=117.72.203.231;Port=3306;Database=LionAbpProDemo9;uid=root;pwd=f616b8803ac7a9a0;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue