39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using StellaOps.Notify.Engine;
|
|
using StellaOps.Notify.Queue;
|
|
using StellaOps.Notify.Storage.Mongo;
|
|
using StellaOps.Notifier.Worker.Options;
|
|
using StellaOps.Notifier.Worker.Processing;
|
|
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
|
|
builder.Configuration
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.AddEnvironmentVariables(prefix: "NOTIFIER_");
|
|
|
|
builder.Logging.ClearProviders();
|
|
builder.Logging.AddSimpleConsole(options =>
|
|
{
|
|
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ ";
|
|
options.UseUtcTimestamp = true;
|
|
});
|
|
|
|
builder.Services.Configure<NotifierWorkerOptions>(builder.Configuration.GetSection("notifier:worker"));
|
|
builder.Services.AddSingleton(TimeProvider.System);
|
|
|
|
var mongoSection = builder.Configuration.GetSection("notifier:storage:mongo");
|
|
builder.Services.AddNotifyMongoStorage(mongoSection);
|
|
|
|
builder.Services.AddNotifyEventQueue(builder.Configuration, "notifier:queue");
|
|
builder.Services.AddHealthChecks().AddNotifyQueueHealthCheck();
|
|
|
|
builder.Services.AddSingleton<INotifyRuleEvaluator, DefaultNotifyRuleEvaluator>();
|
|
builder.Services.AddSingleton<NotifierEventProcessor>();
|
|
builder.Services.AddHostedService<MongoInitializationHostedService>();
|
|
builder.Services.AddHostedService<NotifierEventWorker>();
|
|
|
|
await builder.Build().RunAsync().ConfigureAwait(false);
|