예제 #1
0
 public UrlItemController(UrlShrtDbContext context, IMapper mapper, ILogger <UrlItemController> logger, ISlugConfiguration slugConfiguration)
 {
     _context           = context;
     _mapper            = mapper;
     _logger            = logger;
     _slugConfiguration = slugConfiguration;
 }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UrlShrtDbContext context, ILogger <Startup> logger, Microsoft.Extensions.Hosting.IApplicationLifetime applicationLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/error");
            }
            app.UseForwardedHeaders();
            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            var retries = 10;
            var delayMs = 5000;

            for (int i = 0; i < retries; i++)
            {
                try
                {
                    context.Database.Migrate();
                    break;
                }
                catch (Microsoft.Data.SqlClient.SqlException ex)
                {
                    if (i == retries - 1)
                    {
                        logger.LogError(ex, "Migration failed {retries}/{max_retries}. shutting down, {time} UTC", i + 1, retries, DateTime.UtcNow);
                        applicationLifetime.StopApplication();
                    }
                    else
                    {
                        logger.LogWarning("Migration failed on attempt {retries}/{max_retries}. Delaying exection for {delayMs} ms, {time} UTC", i + 1, retries, delayMs, DateTime.UtcNow);
                    }
                }
                Task.Delay(delayMs);
            }
        }
예제 #3
0
 public AnalyticsController(UrlShrtDbContext context, ILogger <AnalyticsController> logger, IMapper mapper)
 {
     _context = context;
     _logger  = logger;
     _mapper  = mapper;
 }