feat(worker): configure Hangfire worker startup
This commit is contained in:
50
src/IncidentOps.Worker/Program.cs
Normal file
50
src/IncidentOps.Worker/Program.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using Hangfire;
|
||||||
|
using Hangfire.Redis.StackExchange;
|
||||||
|
using IncidentOps.Infrastructure;
|
||||||
|
using IncidentOps.Infrastructure.Auth;
|
||||||
|
using IncidentOps.Infrastructure.Jobs;
|
||||||
|
using IncidentOps.Worker.Jobs;
|
||||||
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
var builder = Host.CreateApplicationBuilder(args);
|
||||||
|
|
||||||
|
// Configure Infrastructure
|
||||||
|
var connectionString = builder.Configuration.GetConnectionString("Postgres")
|
||||||
|
?? throw new InvalidOperationException("Postgres connection string not configured");
|
||||||
|
|
||||||
|
var jwtSettings = new JwtSettings
|
||||||
|
{
|
||||||
|
Issuer = builder.Configuration["Jwt:Issuer"] ?? "incidentops",
|
||||||
|
Audience = builder.Configuration["Jwt:Audience"] ?? "incidentops",
|
||||||
|
SigningKey = builder.Configuration["Jwt:SigningKey"] ?? "not-needed-for-worker",
|
||||||
|
AccessTokenExpirationMinutes = 15,
|
||||||
|
RefreshTokenExpirationDays = 7
|
||||||
|
};
|
||||||
|
|
||||||
|
builder.Services.AddInfrastructure(connectionString, jwtSettings);
|
||||||
|
|
||||||
|
// Configure Hangfire
|
||||||
|
var redisConnectionString = builder.Configuration["Redis:ConnectionString"]
|
||||||
|
?? throw new InvalidOperationException("Redis connection string not configured");
|
||||||
|
|
||||||
|
builder.Services.AddHangfire(configuration => configuration
|
||||||
|
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
|
||||||
|
.UseSimpleAssemblyNameTypeSerializer()
|
||||||
|
.UseRecommendedSerializerSettings()
|
||||||
|
.UseRedisStorage(ConnectionMultiplexer.Connect(redisConnectionString)));
|
||||||
|
|
||||||
|
builder.Services.AddHangfireServer(options =>
|
||||||
|
{
|
||||||
|
options.Queues = ["critical", "default", "low"];
|
||||||
|
options.WorkerCount = Environment.ProcessorCount * 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register job implementations
|
||||||
|
builder.Services.AddScoped<IIncidentTriggeredJob, IncidentTriggeredJob>();
|
||||||
|
builder.Services.AddScoped<ISendWebhookNotificationJob, SendWebhookNotificationJob>();
|
||||||
|
builder.Services.AddScoped<IEscalateIfUnackedJob, EscalateIfUnackedJob>();
|
||||||
|
|
||||||
|
builder.Services.AddHttpClient();
|
||||||
|
|
||||||
|
var host = builder.Build();
|
||||||
|
host.Run();
|
||||||
Reference in New Issue
Block a user