diff --git a/src/Shentun.Sms.HttpApi.Host/Shentun.Sms.HttpApi.Host.csproj b/src/Shentun.Sms.HttpApi.Host/Shentun.Sms.HttpApi.Host.csproj
index 77551ba..e94a9d6 100644
--- a/src/Shentun.Sms.HttpApi.Host/Shentun.Sms.HttpApi.Host.csproj
+++ b/src/Shentun.Sms.HttpApi.Host/Shentun.Sms.HttpApi.Host.csproj
@@ -10,11 +10,14 @@
+
+
+
diff --git a/src/Shentun.Sms.HttpApi.Host/SmsHttpApiHostModule.cs b/src/Shentun.Sms.HttpApi.Host/SmsHttpApiHostModule.cs
index 45de524..4335fd0 100644
--- a/src/Shentun.Sms.HttpApi.Host/SmsHttpApiHostModule.cs
+++ b/src/Shentun.Sms.HttpApi.Host/SmsHttpApiHostModule.cs
@@ -31,8 +31,16 @@ using Volo.Abp.VirtualFileSystem;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Validation;
+using Volo.Abp.BackgroundJobs.Hangfire;
+using Hangfire;
+using Hangfire.PostgreSql;
+using Hangfire.Dashboard;
namespace Shentun.Sms;
+
+///
+/// AbpBackgroundJobsHangfireModule 后台作业
+///
[DependsOn(
typeof(SmsHttpApiModule),
typeof(AbpAutofacModule),
@@ -42,7 +50,8 @@ namespace Shentun.Sms;
typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule),
typeof(AbpAccountWebOpenIddictModule),
typeof(AbpAspNetCoreSerilogModule),
- typeof(AbpSwashbuckleModule)
+ typeof(AbpSwashbuckleModule),
+ typeof(AbpBackgroundJobsHangfireModule)
)]
public class SmsHttpApiHostModule : AbpModule
{
@@ -64,7 +73,7 @@ public class SmsHttpApiHostModule : AbpModule
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
-
+
ConfigureAuthentication(context);
ConfigureBundles();
ConfigureUrls(configuration);
@@ -73,7 +82,7 @@ public class SmsHttpApiHostModule : AbpModule
ConfigureVirtualFileSystem(context);
ConfigureCors(context, configuration);
ConfigureSwaggerServices(context, configuration);
-
+ ConfigureHangfire(context, configuration); //后台作业
//密码策略配置
context.Services.Configure(opt =>
@@ -96,7 +105,7 @@ public class SmsHttpApiHostModule : AbpModule
options.Filters.Add(typeof(CustomerExceptionFilterAttribute));
options.Filters.Add(typeof(CustomerActionFilterAttribute));
- });
+ });
#endregion
@@ -108,6 +117,34 @@ public class SmsHttpApiHostModule : AbpModule
});
}
+ ///
+ /// 后台作业
+ ///
+ ///
+ ///
+ private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
+ {
+ context.Services.AddHangfire(config =>
+ {
+ config.UseStorage(new PostgreSqlStorage(configuration.GetConnectionString("Default")));
+ // config.usep(configuration.GetConnectionString("Default"));
+ //config.UseDashboardMetric(DashboardMetrics.ServerCount)
+ // .UseDashboardMetric(DashboardMetrics.RecurringJobCount)
+ // .UseDashboardMetric(DashboardMetrics.RetriesCount)
+ // .UseDashboardMetric(DashboardMetrics.AwaitingCount)
+ // .UseDashboardMetric(DashboardMetrics.EnqueuedAndQueueCount)
+ // .UseDashboardMetric(DashboardMetrics.ScheduledCount)
+ // .UseDashboardMetric(DashboardMetrics.ProcessingCount)
+ // .UseDashboardMetric(DashboardMetrics.SucceededCount)
+ // .UseDashboardMetric(DashboardMetrics.FailedCount)
+ // .UseDashboardMetric(DashboardMetrics.EnqueuedCountOrNull)
+ // .UseDashboardMetric(DashboardMetrics.FailedCountOrNull)
+ // .UseDashboardMetric(DashboardMetrics.DeletedCount);
+ });
+
+ context.Services.AddHangfireServer();
+ }
+
private void ConfigureAuthentication(ServiceConfigurationContext context)
{
context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
@@ -221,19 +258,19 @@ public class SmsHttpApiHostModule : AbpModule
{
options.AddDefaultPolicy(builder =>
{
- builder
- .WithOrigins(
- configuration["App:CorsOrigins"]
- .Split(",", StringSplitOptions.RemoveEmptyEntries)
- .Select(o => o.RemovePostFix("/"))
- .ToArray()
- )
- .WithAbpExposedHeaders()
- .SetIsOriginAllowedToAllowWildcardSubdomains()
- .AllowAnyHeader()
- .AllowAnyMethod()
- .AllowCredentials();
- });
+ builder
+ .WithOrigins(
+ configuration["App:CorsOrigins"]
+ .Split(",", StringSplitOptions.RemoveEmptyEntries)
+ .Select(o => o.RemovePostFix("/"))
+ .ToArray()
+ )
+ .WithAbpExposedHeaders()
+ .SetIsOriginAllowedToAllowWildcardSubdomains()
+ .AllowAnyHeader()
+ .AllowAnyMethod()
+ .AllowCredentials();
+ });
});
@@ -252,7 +289,7 @@ public class SmsHttpApiHostModule : AbpModule
var commentsFileapi = Path.Combine(baseDirectory, "Shentun.Sms.HttpApi.xml");
options.IncludeXmlComments(commentsFileapi, true);
- });
+ });
#endregion
}
@@ -273,6 +310,28 @@ public class SmsHttpApiHostModule : AbpModule
app.UseErrorPage();
}
+
+ // app.UseHangfireDashboard("/hangfire", new DashboardOptions
+ // {
+ // Authorization = new[] {new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
+ //{
+ // RequireSsl = false,
+ // SslRedirect = false,
+ // LoginCaseSensitive = true,
+ // Users = new []
+ // {
+ // new BasicAuthAuthorizationUser
+ // {
+ // Login = "admin",
+ // PasswordClear = "admin"
+ // }
+ // }
+ //})}
+ // });
+
+
+
+
app.UseCorrelationId();
app.UseStaticFiles();
app.UseRouting();
@@ -301,5 +360,7 @@ public class SmsHttpApiHostModule : AbpModule
app.UseAuditing();
app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints();
+
+
}
}