-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
596 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/StreetNameRegistry.Projections.LastChangedList.Console/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM mcr.microsoft.com/dotnet/runtime-deps:6.0.3 | ||
|
||
# create group & user | ||
RUN addgroup --gid 1000 --system app && adduser --uid 1000 -system app --gid 1000 | ||
|
||
# create work dir and set permissions as WORKDIR sets permissions as root | ||
RUN mkdir /app && chown -R app:app /app | ||
WORKDIR /app | ||
|
||
LABEL maintainer "Digitaal Vlaanderen <[email protected]>" | ||
LABEL registry="streetname-registry" | ||
|
||
COPY / /app | ||
WORKDIR /app | ||
|
||
RUN apt-get update && \ | ||
apt-get install curl jq -y && \ | ||
chmod +x ./init.sh | ||
|
||
# switch to created user | ||
USER app | ||
|
||
ENTRYPOINT ["./init.sh"] |
34 changes: 34 additions & 0 deletions
34
...ections.LastChangedList.Console/Infrastructure/LastChangedListStreetNameCacheValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace StreetNameRegistry.Projections.LastChangedList.Console.Infrastructure | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList; | ||
using Dapper; | ||
using Microsoft.Data.SqlClient; | ||
|
||
public sealed class LastChangedListStreetNameCacheValidator : ICacheValidator | ||
{ | ||
private readonly string _connectionString; | ||
private readonly string _projectionName; | ||
|
||
public LastChangedListStreetNameCacheValidator(string connectionString, string projectionName) | ||
{ | ||
_connectionString = connectionString; | ||
_projectionName = projectionName; | ||
} | ||
|
||
public async Task<bool> CanCache(long position, CancellationToken ct) | ||
{ | ||
await using var connection = new SqlConnection(_connectionString); | ||
|
||
var sql = @"SELECT [Position] | ||
FROM [streetname-registry].[StreetNameRegistryLegacy].[ProjectionStates] | ||
WHERE [Name] = @Name | ||
"; | ||
|
||
var projectionPosition = await connection.ExecuteScalarAsync<int>(sql, new { Name = _projectionName }); | ||
|
||
return projectionPosition >= position; | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...rojections.LastChangedList.Console/Infrastructure/Modules/LastChangedListConsoleModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
namespace StreetNameRegistry.Projections.LastChangedList.Console.Infrastructure.Modules | ||
{ | ||
using System; | ||
using StreetNameRegistry.Infrastructure; | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
using Be.Vlaanderen.Basisregisters.Api.Exceptions; | ||
using Be.Vlaanderen.Basisregisters.DataDog.Tracing.Microsoft; | ||
using Be.Vlaanderen.Basisregisters.DependencyInjection; | ||
using Be.Vlaanderen.Basisregisters.EventHandling; | ||
using Be.Vlaanderen.Basisregisters.EventHandling.Autofac; | ||
using Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList; | ||
using Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore.Autofac; | ||
using Be.Vlaanderen.Basisregisters.Projector; | ||
using Be.Vlaanderen.Basisregisters.Projector.ConnectedProjections; | ||
using Be.Vlaanderen.Basisregisters.Projector.Modules; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using LastChangedListContextMigrationFactory = LastChangedList.LastChangedListContextMigrationFactory; | ||
|
||
public class LastChangedListConsoleModule : Module | ||
{ | ||
private readonly IConfiguration _configuration; | ||
private readonly IServiceCollection _services; | ||
private readonly ILoggerFactory _loggerFactory; | ||
|
||
public LastChangedListConsoleModule( | ||
IConfiguration configuration, | ||
IServiceCollection services, | ||
ILoggerFactory loggerFactory) | ||
{ | ||
_configuration = configuration; | ||
_services = services; | ||
_loggerFactory = loggerFactory; | ||
} | ||
|
||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
_services.RegisterModule(new DataDogModule(_configuration)); | ||
|
||
RegisterProjectionSetup(builder); | ||
|
||
builder | ||
.RegisterType<ProblemDetailsHelper>() | ||
.AsSelf(); | ||
|
||
builder.Populate(_services); | ||
} | ||
|
||
private void RegisterProjectionSetup(ContainerBuilder builder) | ||
{ | ||
builder | ||
.RegisterModule( | ||
new EventHandlingModule( | ||
typeof(DomainAssemblyMarker).Assembly, | ||
EventsJsonSerializerSettingsProvider.CreateSerializerSettings())) | ||
.RegisterModule<EnvelopeModule>() | ||
.RegisterEventstreamModule(_configuration) | ||
.RegisterModule(new ProjectorModule(_configuration)); | ||
|
||
RegisterProjections(builder); | ||
} | ||
|
||
private void RegisterProjections(ContainerBuilder builder) | ||
{ | ||
var logger = _loggerFactory.CreateLogger<LastChangedListConsoleModule>(); | ||
var connectionString = _configuration.GetConnectionString("LastChangedList"); | ||
|
||
builder.RegisterModule(new LastChangedListModule(connectionString, _configuration["DataDog:ServiceName"], _services, _loggerFactory)); | ||
|
||
logger.LogInformation( | ||
"Added {Context} to services:" + | ||
Environment.NewLine + | ||
"\tSchema: {Schema}" + | ||
Environment.NewLine + | ||
"\tTableName: {TableName}", | ||
nameof(LastChangedListContext), LastChangedListContext.Schema, LastChangedListContext.MigrationsHistoryTable); | ||
|
||
builder.Register(c => | ||
new LastChangedListStreetNameCacheValidator( | ||
_configuration.GetConnectionString("LegacyProjections"), | ||
"StreetNameRegistry.Projections.Legacy.StreetNameDetailV2.StreetNameDetailProjectionsV2")) | ||
.AsSelf(); | ||
|
||
builder | ||
.RegisterProjectionMigrator<LastChangedListContextMigrationFactory>( | ||
_configuration, | ||
_loggerFactory) | ||
.RegisterProjectionMigrator<DataMigrationContextMigrationFactory>( | ||
_configuration, | ||
_loggerFactory) | ||
.RegisterProjections<LastChangedProjections, LastChangedListContext>( | ||
context => new LastChangedProjections(context.Resolve<LastChangedListStreetNameCacheValidator>()), | ||
ConnectedProjectionSettings.Default); | ||
} | ||
} | ||
} |
Oops, something went wrong.