From 5f52e16dbd4e33e45b3de55fa6047584bc70cf7f Mon Sep 17 00:00:00 2001 From: Sergey Karmanov Date: Sat, 6 Sep 2025 21:04:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B2=20=D1=82=D0=B5=D0=BB=D0=B5=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SfeduSchedule/Program.cs | 32 ++++++++++++++++++++++++------ SfeduSchedule/SfeduSchedule.csproj | 1 + docker-compose-prod.yml | 4 +++- docker-compose-test.yml | 8 +++++--- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/SfeduSchedule/Program.cs b/SfeduSchedule/Program.cs index 552b504..4bf6b72 100644 --- a/SfeduSchedule/Program.cs +++ b/SfeduSchedule/Program.cs @@ -3,13 +3,17 @@ using Quartz; using SfeduSchedule; using SfeduSchedule.Jobs; using SfeduSchedule.Services; +using X.Extensions.Logging.Telegram.Extensions; var builder = WebApplication.CreateBuilder(args); var configuration = builder.Configuration; -string? preinstsalledJwtToken = configuration["TOKEN"]; +string? preinstalledJwtToken = configuration["TOKEN"]; +string? tgChatId = configuration["TG_CHAT_ID"]; +string? tgToken = configuration["TG_TOKEN"]; string updateJwtCron = configuration["UPDATE_JWT_CRON"] ?? "0 4 * ? * *"; + // создать папку data если не существует var dataDirectory = Path.Combine(AppContext.BaseDirectory, "data"); if (!Directory.Exists(dataDirectory)) @@ -18,7 +22,23 @@ if (!Directory.Exists(dataDirectory)) } GlobalVariables.JwtFilePath = Path.Combine(dataDirectory, "jwt.txt"); -builder.Services.AddOpenApi(); + +builder.Logging.ClearProviders(); +builder.Logging.AddConsole(); +if (!string.IsNullOrEmpty(tgChatId) && !string.IsNullOrEmpty(tgToken)) + builder.Logging.AddTelegram(options => + { + options.ChatId = tgChatId; + options.AccessToken = tgToken; + options.FormatterConfiguration.UseEmoji = true; + options.FormatterConfiguration.ReadableApplicationName = "Sfedu Schedule"; + options.LogLevel = new Dictionary + { + { "Default", LogLevel.Error }, + { "SfeduSchedule.Jobs.UpdateJwtJob", LogLevel.Information } + }; + }); + builder.Services.AddControllers(); builder.Services.AddHttpClient(); @@ -26,7 +46,7 @@ builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration) var jobKey = new JobKey("UpdateJWTJob"); -if (string.IsNullOrEmpty(preinstsalledJwtToken)) +if (string.IsNullOrEmpty(preinstalledJwtToken)) { builder.Services.AddQuartz(q => { @@ -38,7 +58,7 @@ if (string.IsNullOrEmpty(preinstsalledJwtToken)) .WithCronSchedule(updateJwtCron) ); }); - + builder.Services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); } @@ -56,7 +76,7 @@ app.UseForwardedHeaders(); var logger = app.Services.GetRequiredService>(); -if (string.IsNullOrEmpty(preinstsalledJwtToken)) +if (string.IsNullOrEmpty(preinstalledJwtToken)) { var schedulerFactory = app.Services.GetRequiredService(); var scheduler = await schedulerFactory.GetScheduler(); @@ -106,7 +126,7 @@ app.UseStaticFiles(); app.MapGet("/", async context => { context.Response.ContentType = "text/html; charset=utf-8"; - await context.Response.SendFileAsync(Path.Combine(app.Environment.WebRootPath ?? "wwwroot", "index.html")); + await context.Response.SendFileAsync(Path.Combine(app.Environment.WebRootPath, "index.html")); }); app.MapControllers(); diff --git a/SfeduSchedule/SfeduSchedule.csproj b/SfeduSchedule/SfeduSchedule.csproj index 636a263..3e3865b 100644 --- a/SfeduSchedule/SfeduSchedule.csproj +++ b/SfeduSchedule/SfeduSchedule.csproj @@ -15,6 +15,7 @@ + diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index c454b21..2208b32 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -12,7 +12,9 @@ services: - AzureAd:CallbackPath=/signin-oidc - MS_USERNAME=${MS_USERNAME} - MS_PASSWORD=${MS_PASSWORD} - # - TOKEN= + - TG_CHAT_ID=${TG_CHAT_ID} + - TG_TOKEN=${TG_TOKEN} + # - TOKEN=${TOKEN} volumes: - data:/app/data restart: always diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 7be1441..85db821 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -10,9 +10,11 @@ services: - AzureAd:ClientSecret= - AzureAd:Domain=sfedu.onmicrosoft.com - AzureAd:CallbackPath=/signin-oidc - - MS_USERNAME= - - MS_PASSWORD= - # - TOKEN= + - MS_USERNAME=${MS_USERNAME} + - MS_PASSWORD=${MS_PASSWORD} + - TG_CHAT_ID=${TG_CHAT_ID} + - TG_TOKEN=${TG_TOKEN} + # - TOKEN=${TOKEN} volumes: - ./data:/app/data restart: unless-stopped