自动任务优化

parent db020cf1
using FluentScheduler;
using Microsoft.Extensions.DependencyInjection;
using Performance.Services;
using System;
using System.Linq;
using System.Reflection;
//using FluentScheduler;
//using Microsoft.Extensions.DependencyInjection;
//using Performance.Services;
//using System;
//using System.Linq;
//using System.Reflection;
namespace Performance.Api.Configurations
{
public static class FluentSchedulerConfig
{
public static void AddFluentSchedulerConfiguration(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
//namespace Performance.Api.Configurations
//{
// public static class FluentSchedulerConfig
// {
// public static void AddFluentSchedulerConfiguration(this IServiceCollection services)
// {
// if (services == null) throw new ArgumentNullException(nameof(services));
ServiceLocator.Instance = services.BuildServiceProvider();
JobManager.Initialize(new JobRegistry());
// ServiceLocator.Instance = services.BuildServiceProvider();
// JobManager.Initialize(new JobRegistry());
////扫描当前程序集中实现了Registry的类
//var registrys = Assembly.GetExecutingAssembly().GetTypes()
// .Where(t => !t.IsInterface && !t.IsSealed && !t.IsAbstract && typeof(Registry).IsAssignableFrom(t))
// .Select(s => s.Assembly.CreateInstance(s.FullName) as Registry)?.ToArray();
// ////扫描当前程序集中实现了Registry的类
// //var registrys = Assembly.GetExecutingAssembly().GetTypes()
// // .Where(t => !t.IsInterface && !t.IsSealed && !t.IsAbstract && typeof(Registry).IsAssignableFrom(t))
// // .Select(s => s.Assembly.CreateInstance(s.FullName) as Registry)?.ToArray();
//// 注册同步服务
//JobManager.Initialize(registrys);
}
}
}
// //// 注册同步服务
// //JobManager.Initialize(registrys);
// }
// }
//}
using FluentScheduler;
using Microsoft.Extensions.DependencyInjection;
using Performance.Services;
using Performance.Services.ExtractExcelService;
namespace Performance.Api
{
public class ExtractDataJob : IJob
{
private readonly ExtractJobService extractJobService;
{
public ExtractDataJob()
private readonly ExtractJobService _extractJobService;
public ExtractDataJob(ExtractJobService extractJobService)
{
this.extractJobService = ServiceLocator.Instance.GetService<ExtractJobService>();
_extractJobService = extractJobService;
}
public void Execute()
{
extractJobService.Execute();
_extractJobService.Execute();
}
}
}
using FluentScheduler;
using Microsoft.Extensions.DependencyInjection;
using Performance.Services;
using Performance.Services.ExtractExcelService;
namespace Performance.Api
{
public class ExtractGenerateJob : IJob
{
private readonly ExtractJobService extractJobService;
private readonly ExtractJobService _extractJobService;
public ExtractGenerateJob()
public ExtractGenerateJob(ExtractJobService extractJobService)
{
this.extractJobService = ServiceLocator.Instance.GetService<ExtractJobService>();
_extractJobService = extractJobService;
}
public void Execute()
{
extractJobService.ExportFile();
_extractJobService.ExportFile();
}
}
}
using FluentScheduler;
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Caching.Memory;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Performance.Repository;
using Performance.DtoModels;
using Performance.Services;
namespace Performance.Api
{
public class JobRegistry : Registry
{
public JobRegistry()
public JobRegistry(IServiceProvider provider)
{
//Schedule<ExtractDataJob>().ToRunNow().AndEvery(1).Days().At(23, 0);
//Schedule<ExtractDataJob>().ToRunEvery(1).Days().At(23, 0);
Schedule<ExtractGenerateJob>().ToRunEvery(1).Days().At(23, 00);
Schedule(() => provider.GetService<ExtractGenerateJob>()).ToRunEvery(1).Days().At(23, 00);
}
}
}
......@@ -15,6 +15,13 @@
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
<UserSecretsId>e732666b-5531-4cd8-b713-2fe3db31126c</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Files\**" />
<Content Remove="Files\**" />
<EmbeddedResource Remove="Files\**" />
<None Remove="Files\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Performance.DtoModels\Performance.DtoModels.csproj" />
......
using FluentValidation;
using FluentScheduler;
using FluentValidation;
using FluentValidation.AspNetCore;
using MassTransit;
using Microsoft.AspNetCore.Authorization;
......@@ -95,23 +96,9 @@ public void ConfigureServices(IServiceCollection services)
});
});
// fluentscheduler
services.AddFluentSchedulerConfiguration();
//services.AddMassTransit(x =>
//{
// x.AddConsumer<AllotGenerateConsumer>();
// x.UsingInMemory((context, cfg) =>
// {
// cfg.TransportConcurrencyLimit = 20;
// cfg.ConfigureEndpoints(context);
// cfg.ReceiveEndpoint("event-listener", e =>
// {
// e.ConfigureConsumer<AllotGenerateConsumer>(context);
// });
// });
//});
//services.AddMassTransitHostedService();
services.AddTransient<ExtractGenerateJob>();
services.AddTransient<ExtractDataJob>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......@@ -142,6 +129,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
});
app.UseSwaggerSetup(Configuration);
JobManager.Initialize(new JobRegistry(app.ApplicationServices));
}
private void JsonOptions(MvcNewtonsoftJsonOptions json)
......
......@@ -131,7 +131,7 @@
<summary> 绩效库 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.NoData">
<summary> 用户状态 </summary>
<summary> 数据未上传 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.FileUploaded">
<summary> 数据已上传 </summary>
......@@ -3527,21 +3527,11 @@
菜单状态 1 启用 2禁用
</summary>
</member>
<member name="P:Performance.DtoModels.OwnerPerformanceDto.ShouldGiveFee">
<summary>
应发绩效
</summary>
</member>
<member name="P:Performance.DtoModels.OwnerPerformanceDto.ReservedRatio">
<summary>
预留比例
</summary>
</member>
<member name="P:Performance.DtoModels.OwnerPerformanceDto.ReservedRatioFee">
<summary>
预留金额
</summary>
</member>
<member name="P:Performance.DtoModels.OwnerPerformanceDto.RealGiveFee">
<summary>
实发绩效
......
......@@ -47,7 +47,7 @@ public enum DbSrouceType
public enum AllotStates
{
/// <summary> 用户状态 </summary>
/// <summary> 数据未上传 </summary>
[Description("数据未上传")]
NoData = 0,
/// <summary> 数据已上传 </summary>
......
using System;
using System.Collections.Generic;
using System.Text;
//using System;
//using System.Collections.Generic;
//using System.Text;
namespace Performance.Services
{
public static class ServiceLocator
{
public static IServiceProvider Instance { get; set; }
}
}
//namespace Performance.Services
//{
// public static class ServiceLocator
// {
// public static IServiceProvider Instance { get; set; }
// }
//}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment