Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Recep Güneş committed Sep 1, 2023
1 parent d1f5c37 commit e570a48
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@ MigrationBackup/
FodyWeavers.xsd

# Rider
.idea
.idea
4 changes: 2 additions & 2 deletions external-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ services:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
ports:
- 9200:9200
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
# volumes:
# - elasticsearch-data:/usr/share/elasticsearch/data
environment:
- xpack.monitoring.enabled=true
- xpack.watcher.enabled=false
Expand Down
2 changes: 2 additions & 0 deletions internal-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ services:
dockerfile: src/Gateway/Gateway.WebAPI/Dockerfile
environment:
ASPNETCORE_ENVIRONMENT: Production
ports:
- 5043:80
depends_on:
- expiry_check_api
- shortener_api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public async Task<UrlEnumerableDto> Handle(GetAllUrlsFromBufferQuery request, Ca
logger.LogInformation($"Request was handled by {nameof(GetAllUrlsFromBufferQueryHandler)}");
var sql = @"SELECT ""Id"", ""LongUrl"", ""ShortPath"", ""CreatedDate"", ""LastRequestedDate"", ""RequestCounter"", ""ExpireDate"", ""IsPublic""
FROM public.""Urls""
WHERE ""IsPublic"" = true;";
WHERE ""IsPublic"" = true
ORDER BY ""CreatedDate"" DESC;
";
var result = await connection.QueryAsync<UrlDto>(sql);
logger.LogInformation($"Executed Query:{Environment.NewLine}\t{sql}");
ArgumentNullException.ThrowIfNull(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public async Task<ReachUrlDto> Handle(ReachUrlCommand request, CancellationToken
var url = await dbContext.Urls.FirstOrDefaultAsync(p => p.ShortPath == request.ShortPath);
if (url == null)
{
return new() { Message = "an error occurred" };
return new() { Message = string.Empty };
}
url.RequestCounter++;
url.LastRequestedDate = DateTime.UtcNow;
await dbContext.SaveChangesAsync();
return new() { Message = "it is okay" };
return new() { Message = url.LongUrl };
}
}
}
1 change: 0 additions & 1 deletion src/Shortener/Infrastructure/Services/OutboxWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private async Task PublishOutboxMessages(CancellationToken stoppingToken)
_logger.LogWarning(ex.ToJsonString());
}
}

await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
Expand Down
34 changes: 0 additions & 34 deletions src/Utils/Shared/Extensions/SharedExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System.Collections;
using System.Reflection;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Sinks.Elasticsearch;

namespace Shared.Extensions
{
Expand All @@ -29,35 +25,5 @@ public static string ToJsonString(this Exception ex)
var jsonException = JsonSerializer.Serialize(exceptionDetails, new JsonSerializerOptions { WriteIndented = true });
return jsonException;
}

public static void ConfigureLogging()
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json",
optional: true)
.Build();

Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.WriteTo.Debug()
.WriteTo.Console()
.WriteTo.Elasticsearch(ConfigureElasticSink(configuration, environment))
.Enrich.WithProperty("Environment", environment)
.ReadFrom.Configuration(configuration)
.CreateLogger();
}

private static ElasticsearchSinkOptions ConfigureElasticSink(IConfigurationRoot configuration, string environment)
{
return new ElasticsearchSinkOptions(new Uri(configuration["ElasticConfiguration:Uri"]))
{
AutoRegisterTemplate = true,
IndexFormat = $"{Assembly.GetExecutingAssembly().GetName().Name.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}-{DateTime.UtcNow:yyyy-MM}"
};
}
}
}
9 changes: 1 addition & 8 deletions src/Utils/Shared/Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,5 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="9.0.3" />
</ItemGroup>


</Project>

0 comments on commit e570a48

Please sign in to comment.