cronjob พ้นราชการ
This commit is contained in:
parent
dd6471ddf1
commit
cfaf90cb01
6 changed files with 171 additions and 20 deletions
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AWSSDK.S3" Version="3.7.201.7" />
|
||||
<PackageReference Include="Hangfire" Version="1.8.5" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.5" />
|
||||
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
|
||||
|
|
|
|||
|
|
@ -561,7 +561,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
var data = new RetirementProfile
|
||||
{
|
||||
Order = num,
|
||||
Remove = "PENDING",
|
||||
Remove = "ADD",
|
||||
RetirementPeriod = retire,
|
||||
Profile = profile,
|
||||
CreatedUserId = UserId ?? "System Administrator",
|
||||
|
|
|
|||
16
BMA.EHR.Retirement.Service/Filters/CustomAuthorizeFilter.cs
Normal file
16
BMA.EHR.Retirement.Service/Filters/CustomAuthorizeFilter.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using Hangfire.Dashboard;
|
||||
|
||||
namespace BMA.EHR.Retirement.Service.Filters
|
||||
{
|
||||
public class CustomAuthorizeFilter : IDashboardAuthorizationFilter
|
||||
{
|
||||
public bool Authorize([NotNull] DashboardContext context)
|
||||
{
|
||||
//var httpcontext = context.GetHttpContext();
|
||||
//return httpcontext.User.Identity.IsAuthenticated;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -10,11 +10,17 @@ using Microsoft.AspNetCore.Mvc.Versioning;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Hangfire;
|
||||
using Hangfire.Common;
|
||||
using Hangfire.MySql;
|
||||
using Serilog;
|
||||
using Serilog.Exceptions;
|
||||
using Serilog.Sinks.Elasticsearch;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Transactions;
|
||||
using BMA.EHR.Retirement.Service.Filters;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
{
|
||||
|
|
@ -89,6 +95,30 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||
|
||||
// Register DbContext
|
||||
var defaultConnection = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
builder.Services.AddDbContext<ApplicationDBContext>(options =>
|
||||
options.UseMySql(defaultConnection, ServerVersion.AutoDetect(defaultConnection)));
|
||||
builder.Services.AddHealthChecks();
|
||||
// Add Hangfire services.
|
||||
builder.Services.AddHangfire(configuration => configuration
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseStorage(
|
||||
new MySqlStorage(
|
||||
defaultConnection,
|
||||
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),
|
||||
TablesPrefix = "Hangfire"
|
||||
})));
|
||||
builder.Services.AddHealthChecks();
|
||||
}
|
||||
|
||||
|
|
@ -120,6 +150,17 @@ var app = builder.Build();
|
|||
app.UseStaticFiles();
|
||||
app.MapControllers();
|
||||
app.UseMiddleware<ErrorHandlerMiddleware>();
|
||||
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
|
||||
{
|
||||
Authorization = new[] { new CustomAuthorizeFilter() }
|
||||
});
|
||||
var manager = new RecurringJobManager();
|
||||
if (manager != null)
|
||||
{
|
||||
manager.AddOrUpdate("แจ้งเตือนระบบปลดออก", Job.FromExpression<RetirementRepository>(x => x.NotifyDischarge()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
manager.AddOrUpdate("แจ้งเตือนระบบไล่ออก", Job.FromExpression<RetirementRepository>(x => x.NotifyExpulsion()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
manager.AddOrUpdate("แจ้งเตือนระบบให้ออก", Job.FromExpression<RetirementRepository>(x => x.NotifyOut()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
}
|
||||
|
||||
// apply migrations
|
||||
await using var scope = app.Services.CreateAsyncScope();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue