74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
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<Query, Mutation>();
|
|
builder.Services.AddHealthChecks();
|
|
builder.Services.AddTransient<JobManagerService>();
|
|
|
|
#region Database
|
|
|
|
builder.Services.RegisterDbContext<SchedulerServiceDbContext>(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<PostgreSQLDelegate>();
|
|
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<SchedulerServiceDbContext>();
|
|
dbContext.UpdateDatabase();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.MapHealthChecks("/healthz");
|
|
|
|
app.MapGraphQL();
|
|
|
|
app.RunWithGraphQLCommands(args);
|
|
}
|
|
} |