|
@@ -1,12 +1,8 @@
|
|
|
using Autofac.Core;
|
|
using Autofac.Core;
|
|
|
using Business.Core.MongoDBHelper;
|
|
using Business.Core.MongoDBHelper;
|
|
|
using Business.EntityFrameworkCore;
|
|
using Business.EntityFrameworkCore;
|
|
|
-using Business.HangFire;
|
|
|
|
|
using Business.MultiTenancy;
|
|
using Business.MultiTenancy;
|
|
|
-using Hangfire;
|
|
|
|
|
-using Hangfire.Dashboard.BasicAuthorization;
|
|
|
|
|
-using Hangfire.MySql;
|
|
|
|
|
-using Hangfire.MySql.Core;
|
|
|
|
|
|
|
+using Business.Quartz;
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.AspNetCore.Cors;
|
|
@@ -16,13 +12,13 @@ using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
using Microsoft.OpenApi.Models;
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
|
+using Quartz;
|
|
|
using StackExchange.Redis;
|
|
using StackExchange.Redis;
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
using System.Data;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
-using System.Security.Cryptography.Pkcs;
|
|
|
|
|
using Volo.Abp;
|
|
using Volo.Abp;
|
|
|
using Volo.Abp.AspNetCore.ExceptionHandling;
|
|
using Volo.Abp.AspNetCore.ExceptionHandling;
|
|
|
using Volo.Abp.AspNetCore.MultiTenancy;
|
|
using Volo.Abp.AspNetCore.MultiTenancy;
|
|
@@ -67,10 +63,10 @@ namespace Business
|
|
|
//ConfigureRedis(context, configuration, hostingEnvironment);
|
|
//ConfigureRedis(context, configuration, hostingEnvironment);
|
|
|
ConfigureCors(context, configuration);
|
|
ConfigureCors(context, configuration);
|
|
|
ConfigureSwaggerServices(context, configuration);
|
|
ConfigureSwaggerServices(context, configuration);
|
|
|
- ConfigureHangfire(context, configuration);
|
|
|
|
|
|
|
+ ConfigureQuartz(context, configuration);
|
|
|
//MongoDB依赖注入
|
|
//MongoDB依赖注入
|
|
|
ConfigureMongoDB(configuration);
|
|
ConfigureMongoDB(configuration);
|
|
|
- if(hostingEnvironment.IsDevelopment())
|
|
|
|
|
|
|
+ if (hostingEnvironment.IsDevelopment())
|
|
|
{
|
|
{
|
|
|
Configure<AbpExceptionHandlingOptions>(options =>
|
|
Configure<AbpExceptionHandlingOptions>(options =>
|
|
|
{
|
|
{
|
|
@@ -95,31 +91,31 @@ namespace Business
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
|
|
|
|
|
|
|
+ private void ConfigureQuartz(ServiceConfigurationContext context, IConfiguration configuration)
|
|
|
{
|
|
{
|
|
|
- context.Services.AddHangfire(config =>
|
|
|
|
|
|
|
+ context.Services.AddQuartz(q =>
|
|
|
{
|
|
{
|
|
|
- //config.UseStorage(new MySqlStorage(configuration.GetConnectionString("Business"),new MySqlStorageOptions
|
|
|
|
|
- //{
|
|
|
|
|
- // TransactionIsolationLevel =IsolationLevel.ReadCommitted,
|
|
|
|
|
- // QueuePollInterval = TimeSpan.FromSeconds(15),
|
|
|
|
|
- // JobExpirationCheckInterval = TimeSpan.FromHours(1),
|
|
|
|
|
- // CountersAggregateInterval = TimeSpan.FromMinutes(5),
|
|
|
|
|
- // PrepareSchemaIfNecessary = true,
|
|
|
|
|
- // DashboardJobListLimit = 50000,
|
|
|
|
|
- // TransactionTimeout = TimeSpan.FromMinutes(1),
|
|
|
|
|
- // TablePrefix = "Hangfire"
|
|
|
|
|
- //}));
|
|
|
|
|
- config.UseStorage(new MySqlStorage(configuration.GetConnectionString("Default"), new MySqlStorageOptions
|
|
|
|
|
- {
|
|
|
|
|
- QueuePollInterval = TimeSpan.FromSeconds(15),
|
|
|
|
|
- JobExpirationCheckInterval = TimeSpan.FromHours(1),
|
|
|
|
|
- CountersAggregateInterval = TimeSpan.FromMinutes(5),
|
|
|
|
|
- PrepareSchemaIfNecessary = true,
|
|
|
|
|
- DashboardJobListLimit = 50000,
|
|
|
|
|
- TransactionTimeout = TimeSpan.FromMinutes(1),
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ q.UseMicrosoftDependencyInjectionScopedJobFactory();
|
|
|
|
|
+ // Just use the name of your job that you created in the Jobs folder.
|
|
|
|
|
+ var jobKey = new JobKey("DemoJob");
|
|
|
|
|
+ q.AddJob<SyncMySQLDataJob>(opts => opts.WithIdentity(jobKey));
|
|
|
|
|
+
|
|
|
|
|
+ q.AddTrigger(opts => opts
|
|
|
|
|
+ .ForJob(jobKey)
|
|
|
|
|
+ .WithIdentity("DemoJob-trigger")
|
|
|
|
|
+ .WithCronSchedule("0 45 11 * * ?")
|
|
|
|
|
+ .WithDescription("定时同步MySQL基础数据到MongoDB"));
|
|
|
});
|
|
});
|
|
|
|
|
+ context.Services.AddQuartzServer(options =>
|
|
|
|
|
+ {
|
|
|
|
|
+ // when shutting down we want jobs to complete gracefully
|
|
|
|
|
+ options.WaitForJobsToComplete = true;
|
|
|
|
|
+ });
|
|
|
|
|
+ //context.Services.AddQuartzHostedService(options =>
|
|
|
|
|
+ //{
|
|
|
|
|
+ // // when shutting down we want jobs to complete gracefully
|
|
|
|
|
+ // options.WaitForJobsToComplete = true;
|
|
|
|
|
+ //});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -129,7 +125,8 @@ namespace Business
|
|
|
/// <param name="configuration"></param>
|
|
/// <param name="configuration"></param>
|
|
|
private void ConfigureMongoDB(IConfiguration configuration)
|
|
private void ConfigureMongoDB(IConfiguration configuration)
|
|
|
{
|
|
{
|
|
|
- Configure<Config>(options => {
|
|
|
|
|
|
|
+ Configure<Config>(options =>
|
|
|
|
|
+ {
|
|
|
options.connectstring = configuration.GetConnectionString("MongoDB");
|
|
options.connectstring = configuration.GetConnectionString("MongoDB");
|
|
|
options.database = configuration.GetConnectionString("DBName");
|
|
options.database = configuration.GetConnectionString("DBName");
|
|
|
});
|
|
});
|
|
@@ -293,30 +290,6 @@ namespace Business
|
|
|
app.UseAbpSerilogEnrichers();
|
|
app.UseAbpSerilogEnrichers();
|
|
|
app.UseUnitOfWork();
|
|
app.UseUnitOfWork();
|
|
|
app.UseConfiguredEndpoints();
|
|
app.UseConfiguredEndpoints();
|
|
|
- //app.UseHangfireServer();
|
|
|
|
|
- app.UseHangfireDashboard(options: new DashboardOptions
|
|
|
|
|
- {
|
|
|
|
|
- Authorization = new[]
|
|
|
|
|
- {
|
|
|
|
|
- new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
|
|
|
|
|
- {
|
|
|
|
|
- RequireSsl = false,
|
|
|
|
|
- SslRedirect = false,
|
|
|
|
|
- LoginCaseSensitive = true,
|
|
|
|
|
- Users = new []
|
|
|
|
|
- {
|
|
|
|
|
- new BasicAuthAuthorizationUser
|
|
|
|
|
- {
|
|
|
|
|
- Login = configuration["Hangfire:Login"],
|
|
|
|
|
- PasswordClear = configuration["Hangfire:Password"]
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- DashboardTitle = "任务调度中心"
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- RecurringJob.AddOrUpdate<IHangFireJobService>(a=>a.SyncDataMySQLData(),CronType.Day(0,0,1),TimeZoneInfo.Local);
|
|
|
|
|
AsyncHelper.RunSync(async () =>
|
|
AsyncHelper.RunSync(async () =>
|
|
|
{
|
|
{
|
|
|
using (var scope = context.ServiceProvider.CreateScope())
|
|
using (var scope = context.ServiceProvider.CreateScope())
|