using FictionArchive.Service.SchedulerService.GraphQL; using FictionArchive.Service.SchedulerService.Services; using FictionArchive.Service.Shared.Extensions; using FictionArchive.Service.Shared.Services.EventBus.Implementations; using Quartz; using Quartz.Impl.AdoJobStore; namespace FictionArchive.Service.SchedulerService; public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); // Services builder.Services.AddDefaultGraphQl(); builder.Services.AddHealthChecks(); builder.Services.AddTransient(); #region Database builder.Services.RegisterDbContext(builder.Configuration.GetConnectionString("DefaultConnection")); #endregion #region Event Bus builder.Services.AddRabbitMQ(opt => { builder.Configuration.GetSection("RabbitMQ").Bind(opt); }); #endregion #region Quartz builder.Services.AddQuartz(opt => { opt.UsePersistentStore(pso => { pso.UsePostgres(pgsql => { pgsql.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection"); pgsql.UseDriverDelegate(); pgsql.TablePrefix = "quartz.qrtz_"; // Needed for Postgres due to the differing schema used }); pso.UseNewtonsoftJsonSerializer(); }); }); builder.Services.AddQuartzHostedService(opt => { opt.WaitForJobsToComplete = true; }); #endregion var app = builder.Build(); using (var scope = app.Services.CreateScope()) { var dbContext = scope.ServiceProvider.GetRequiredService(); dbContext.UpdateDatabase(); } app.UseHttpsRedirection(); app.MapHealthChecks("/healthz"); app.MapGraphQL(); app.RunWithGraphQLCommands(args); } }