2023-02-14 17:51:22 -08:00
|
|
|
using Hangfire;
|
|
|
|
using Hangfire.MemoryStorage;
|
2023-02-26 09:40:04 -08:00
|
|
|
using Newsbot.Collector.Domain.Consts;
|
2023-03-05 22:33:41 -08:00
|
|
|
using Newsbot.Collector.Domain.Models;
|
|
|
|
using Newsbot.Collector.Services.Jobs;
|
|
|
|
using Serilog;
|
2023-02-26 09:40:04 -08:00
|
|
|
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
|
|
.WriteTo.Console()
|
|
|
|
.CreateLogger();
|
|
|
|
|
|
|
|
Log.Information("Starting up");
|
2023-02-14 17:51:22 -08:00
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
2023-02-26 09:40:04 -08:00
|
|
|
// Define Logger
|
|
|
|
builder.Host.UseSerilog(); // <-- Add this line
|
2023-02-14 17:51:22 -08:00
|
|
|
|
|
|
|
// Build the conifg
|
2023-02-19 21:39:03 -08:00
|
|
|
var config = GetConfiguration();
|
2023-02-14 17:51:22 -08:00
|
|
|
builder.Configuration.AddConfiguration(config);
|
|
|
|
|
2023-02-26 09:40:04 -08:00
|
|
|
// Configure Hangfire
|
2023-02-14 17:51:22 -08:00
|
|
|
builder.Services.AddHangfire(f => f.UseMemoryStorage());
|
|
|
|
builder.Services.AddHangfireServer();
|
2023-02-26 09:40:04 -08:00
|
|
|
GlobalConfiguration.Configuration.UseSerilogLogProvider();
|
2023-02-14 17:51:22 -08:00
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
2023-02-26 09:40:04 -08:00
|
|
|
builder.Services.Configure<ConnectionStrings>(config.GetSection("ConnectionStrings"));
|
|
|
|
|
2023-02-14 17:51:22 -08:00
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
app.UseHangfireDashboard();
|
2023-02-26 09:40:04 -08:00
|
|
|
SetupRecurringJobs(config, Log.Logger);
|
2023-02-14 17:51:22 -08:00
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
app.Run();
|
2023-02-19 21:39:03 -08:00
|
|
|
|
2023-02-26 09:40:04 -08:00
|
|
|
|
2023-02-19 21:39:03 -08:00
|
|
|
static IConfiguration GetConfiguration()
|
|
|
|
{
|
|
|
|
return new ConfigurationBuilder()
|
|
|
|
.AddJsonFile("appsettings.json", true)
|
|
|
|
.AddEnvironmentVariables()
|
|
|
|
.Build();
|
|
|
|
}
|
|
|
|
|
2023-02-26 09:40:04 -08:00
|
|
|
static void SetupRecurringJobs(IConfiguration configuration, Serilog.ILogger logger)
|
2023-02-19 21:39:03 -08:00
|
|
|
{
|
2023-03-05 22:33:41 -08:00
|
|
|
//RecurringJob.AddOrUpdate<HelloWorldJob>("Example", x => x.InitAndExecute(new HelloWorldJobOptions
|
|
|
|
//{
|
|
|
|
// Message = "Hello from the background!"
|
|
|
|
//}), "0/1 * * * *");
|
|
|
|
|
2023-02-26 09:40:04 -08:00
|
|
|
RecurringJob.AddOrUpdate<RssWatcherJob>("RSS", x => x.InitAndExecute(new RssWatcherJobOptions
|
2023-02-19 21:39:03 -08:00
|
|
|
{
|
2023-02-26 09:40:04 -08:00
|
|
|
ConnectionString = configuration.GetSection(ConfigConnectionStringConst.Database).Value ?? ""
|
|
|
|
}), "15 0-23 * * *");
|
2023-03-05 22:33:41 -08:00
|
|
|
|
|
|
|
RecurringJob.AddOrUpdate<DiscordNotificationJob>("Discord Alerts", x => x.InitAndExecute(new DiscordNotificationJobOptions
|
|
|
|
{
|
|
|
|
DatabaseConnectionString = configuration.GetSection(ConfigConnectionStringConst.Database).Value ?? ""
|
|
|
|
}), "5/10 * * * *");
|
2023-02-19 21:39:03 -08:00
|
|
|
}
|