From 17cec6dd643071dadd11688cd16513c7ffff9fa7 Mon Sep 17 00:00:00 2001 From: Lisoveliy Date: Fri, 25 Jul 2025 19:04:38 +0300 Subject: [PATCH 1/2] fix: removed async in lock tasks --- JOBot.Backend/Program.cs | 2 +- JOBot.Backend/Startup.cs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/JOBot.Backend/Program.cs b/JOBot.Backend/Program.cs index 6e070ab..95467a3 100644 --- a/JOBot.Backend/Program.cs +++ b/JOBot.Backend/Program.cs @@ -4,7 +4,7 @@ var builder = WebApplication.CreateBuilder(args); var startup = new Startup(builder.Configuration); -await startup.ConfigureServices(builder.Services); +startup.ConfigureServices(builder.Services); var app = builder.Build(); startup.Configure(app, app.Environment); diff --git a/JOBot.Backend/Startup.cs b/JOBot.Backend/Startup.cs index 9cb2137..3c6c2ab 100644 --- a/JOBot.Backend/Startup.cs +++ b/JOBot.Backend/Startup.cs @@ -12,29 +12,29 @@ public class Startup(IConfiguration configuration) { private IConfiguration Configuration { get; } = configuration; - public async Task ConfigureServices(IServiceCollection services) + public void ConfigureServices(IServiceCollection services) { services.AddGrpc(); services.AddGrpcReflection(); services.AddControllers(); services.AddLogging(); + + services.AddDbContext(options => + options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL"))); - var rabbitMqConnection = await new ConnectionFactory + var rabbitMqConnection = new ConnectionFactory { HostName = "rabbitmq" - }.CreateConnectionAsync(); - var channel = await rabbitMqConnection.CreateChannelAsync(); - await channel.QueueDeclareAsync( + }.CreateConnectionAsync().Result; + var channel = rabbitMqConnection.CreateChannelAsync().Result; + channel.QueueDeclareAsync( RabbitQueues.AuthQueue, false, false, false, - arguments: null); + arguments: null).Wait(); services.AddSingleton(channel); - services.AddDbContext(options => - options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL"))); - services.Configure(Configuration.GetSection(HeadHunterConfig.SectionName)); services.AddScoped(); From 176cf194cda88e58958da5850f45ee5262af4777 Mon Sep 17 00:00:00 2001 From: Lisoveliy Date: Fri, 25 Jul 2025 19:43:14 +0300 Subject: [PATCH 2/2] fix: fixed migration by lazy load of rabbitmq --- JOBot.Backend/Startup.cs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/JOBot.Backend/Startup.cs b/JOBot.Backend/Startup.cs index 3c6c2ab..38366f5 100644 --- a/JOBot.Backend/Startup.cs +++ b/JOBot.Backend/Startup.cs @@ -22,18 +22,22 @@ public class Startup(IConfiguration configuration) services.AddDbContext(options => options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL"))); - var rabbitMqConnection = new ConnectionFactory + + services.AddSingleton(x => { - HostName = "rabbitmq" - }.CreateConnectionAsync().Result; - var channel = rabbitMqConnection.CreateChannelAsync().Result; - channel.QueueDeclareAsync( - RabbitQueues.AuthQueue, - false, - false, - false, - arguments: null).Wait(); - services.AddSingleton(channel); + var rabbitMqConnection = new ConnectionFactory + { + HostName = "rabbitmq" + }.CreateConnectionAsync().Result; + var channel = rabbitMqConnection.CreateChannelAsync().Result; + channel.QueueDeclareAsync( + RabbitQueues.AuthQueue, + false, + false, + false, + arguments: null).Wait(); + return channel; + }); services.Configure(Configuration.GetSection(HeadHunterConfig.SectionName));