Files
Web_IoTBase_Sever_Prod/NewCRICS/Program.cs
2025-12-11 14:04:39 +08:00

126 lines
4.7 KiB
C#

using NewCRICS.Jobs;
using Orleans.Configuration;
using Quartz;
namespace NewCRICS
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseOrleans(ooo =>
{
// 在 Orleans 客户端和服务端配置中添加性能调优
ooo.Configure<GrainCollectionOptions>(options =>
{
options.CollectionAge = TimeSpan.FromMinutes(10); // 延长Grain生命周期
options.DeactivationTimeout = TimeSpan.FromMinutes(10);
});
ooo.Configure<Orleans.Configuration.SchedulingOptions>(options =>
{
//options.MaxActiveThreads = Math.Max(4, Environment.ProcessorCount * 2);
options.MaxPendingWorkItemsSoftLimit = 10000;
options.DelayWarningThreshold = TimeSpan.FromSeconds(5);
});
ooo.UseLocalhostClustering();
ooo.AddRedisGrainStorage("RedisStorage", options =>
{
options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions
{
EndPoints = { "localhost:6379" },
AbortOnConnectFail = false,
};
});
});
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddQuartz(q =>
{
var jobKey = new JobKey("CacheSaveJob");
q.AddJob<CacheSave>(opts => opts.WithIdentity(jobKey));
q.AddTrigger(opts => opts
.ForJob(jobKey)
.WithIdentity("CacheSaveJob-trigger")
.WithCalendarIntervalSchedule(x =>
{
x.WithIntervalInMinutes(1).Build();
})
);
#region
//var jobKey1 = new JobKey("Cache_Save");
//q.AddJob<CacheSave>(opts => opts.WithIdentity(jobKey1));
//q.AddTrigger(opts => opts
// .ForJob(jobKey1)
// .WithIdentity("CacheSaveJob-trigger")
// .StartAt(DateBuilder.TodayAt(h, m, s))
// .WithCalendarIntervalSchedule(x => x
// .WithIntervalInDays(1)
// .InTimeZone(TimeZoneInfo.Local))
//);
//q.AddTrigger(opts => opts
// .ForJob(jobKey1)
// .WithIdentity("ExcelGenerateJob-trigger")
// .WithCronSchedule("0 0 17 * * ?", (schedule) =>
// {
// schedule.WithMisfireHandlingInstructionDoNothing().InTimeZone(TimeZoneInfo.Local);
// }) // 每天17:00
//);
//var jobKey2 = new JobKey("ScanExcel");
//q.AddJob<ExcelScan>(opts => opts.WithIdentity(jobKey2));
//q.AddTrigger(opts => opts
// .ForJob(jobKey2)
// .WithIdentity("ExcelScan-trigger")
// .WithCalendarIntervalSchedule(x =>
// {
// x.WithIntervalInSeconds(30).Build();
// })
//);
//var jobKey3 = new JobKey("DeleteFile");
//q.AddJob<ExcelScan>(opts => opts.WithIdentity(jobKey3));
//q.AddTrigger(opts => opts
// .ForJob(jobKey3)
// .WithIdentity("DeleteFile-trigger")
// .WithCronSchedule("0 0 1 * * ?", (schedule) =>
// {
// schedule.WithMisfireHandlingInstructionDoNothing().InTimeZone(TimeZoneInfo.Local);
// }) // 每天17:00
//);
#endregion
});
builder.Services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
}
}
}