| | 1 | | using Hangfire; |
| | 2 | | using Syki.Daemon.Tasks; |
| | 3 | | using Syki.Daemon.Configs; |
| | 4 | | using Hangfire.MemoryStorage; |
| | 5 | |
|
| | 6 | | namespace Syki.Daemon; |
| | 7 | |
|
| 1 | 8 | | public class Startup(IConfiguration configuration) |
| | 9 | | { |
| | 10 | | public void ConfigureServices(IServiceCollection services) |
| | 11 | | { |
| 1 | 12 | | services.AddServicesConfigs(); |
| | 13 | |
|
| 1 | 14 | | services.AddHostedService<PostgresListener>(); |
| | 15 | |
|
| 1 | 16 | | services.AddHangfire(x => |
| 1 | 17 | | { |
| 1 | 18 | | x.UseMemoryStorage(); |
| 1 | 19 | | x.UseRecommendedSerializerSettings(); |
| 1 | 20 | | x.UseSimpleAssemblyNameTypeSerializer(); |
| 2 | 21 | | }); |
| | 22 | |
|
| 1 | 23 | | services.AddHangfireServer(x => |
| 1 | 24 | | { |
| 1 | 25 | | x.ServerName = "Daemon"; |
| 1 | 26 | | x.SchedulePollingInterval = TimeSpan.FromSeconds(1); |
| 2 | 27 | | }); |
| 1 | 28 | | } |
| | 29 | |
|
| | 30 | | public void Configure(IApplicationBuilder app) |
| | 31 | | { |
| 1 | 32 | | BackgroundJob.Enqueue<SykiTasksProcessor>(x => x.Run()); |
| | 33 | |
|
| 1 | 34 | | app.UseRouting(); |
| 1 | 35 | | app.UseStaticFiles(); |
| | 36 | |
|
| 1 | 37 | | app.UseEndpoints(x => |
| 1 | 38 | | { |
| 1 | 39 | | x.MapGet("/health", () => Results.Ok(new { Status = "Healthy" })); |
| 2 | 40 | | }); |
| | 41 | |
|
| 1 | 42 | | app.UseHangfireDashboard( |
| 1 | 43 | | pathMatch: "", |
| 1 | 44 | | options: new DashboardOptions |
| 1 | 45 | | { |
| 1 | 46 | | FaviconPath = "/favicon.ico", |
| 1 | 47 | | Authorization = [ new HangfireAuthFilter(configuration.Hangfire().User, configuration.Hangfire().Passwor |
| 1 | 48 | | } |
| 1 | 49 | | ); |
| 1 | 50 | | } |
| | 51 | | } |