cronjob + ลงเวลากรณีพิเดศษ
This commit is contained in:
parent
72f64728bb
commit
e76d994098
16 changed files with 1518 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using BMA.EHR.Application;
|
||||
using BMA.EHR.Application;
|
||||
using BMA.EHR.Leave.Service;
|
||||
using BMA.EHR.Domain.Middlewares;
|
||||
using BMA.EHR.Infrastructure;
|
||||
|
|
@ -15,6 +15,12 @@ using Serilog.Exceptions;
|
|||
using Serilog.Sinks.Elasticsearch;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Hangfire;
|
||||
using Hangfire.MySql;
|
||||
using System.Transactions;
|
||||
using BMA.EHR.Leave.Service.Filters;
|
||||
using Hangfire.Common;
|
||||
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
{
|
||||
|
|
@ -93,6 +99,29 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
// Add Hangfire services.
|
||||
var defaultConnection = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
|
||||
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.AddHangfireServer();
|
||||
}
|
||||
|
||||
var app = builder.Build();
|
||||
|
|
@ -124,6 +153,18 @@ var app = builder.Build();
|
|||
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<UserDutyTimeRepository>(x => x.UpdateUserDutyTime()), Cron.Daily(6, 0), TimeZoneInfo.Local);
|
||||
}
|
||||
|
||||
// apply migrations
|
||||
await using var scope = app.Services.CreateAsyncScope();
|
||||
await using var db = scope.ServiceProvider.GetRequiredService<LeaveDbContext>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue