Skip to content

Commit

Permalink
feat: or-1349 add rebuild all publiek projections
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenGreenstack committed Jan 24, 2024
1 parent 9029fbe commit 39c9eb2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public PublicProjectionHostHttpClient(HttpClient httpClient)
_httpClient = httpClient;
}

public async Task<HttpResponseMessage> RebuildAllProjections(CancellationToken cancellationToken)
=> await _httpClient.PostAsync(requestUri: "/v1/projections/all/rebuild", content: null, cancellationToken);
public async Task<HttpResponseMessage> RebuildDetailProjection(CancellationToken cancellationToken)
=> await _httpClient.PostAsync(requestUri: "/v1/projections/detail/rebuild", content: null, cancellationToken);

Expand All @@ -27,4 +29,6 @@ public void Dispose()
{
_httpClient.Dispose();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public async Task<IActionResult> GetAdminProjectionStatus(CancellationToken canc
return await OkObjectOrForwardedResponse(cancellationToken, response);
}

[HttpPost("public/all/rebuild")]
public async Task<IActionResult> RebuildPublicAllProjections(CancellationToken cancellationToken)
{
var response = await _publicHttpClient.RebuildAllProjections(cancellationToken);

return await OkOrForwardedResponse(cancellationToken, response);
}

[HttpPost("public/detail/rebuild")]
public async Task<IActionResult> RebuildPublicProjectionDetail(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,43 @@ public static void AddProjectionEndpoints(this WebApplication app, RebuildConfig
{
var shardTimeout = TimeSpan.FromMinutes(configurationSection.TimeoutInMinutes);

app.MapPost(
pattern: "v1/projections/all/rebuild",
handler: async (
IDocumentStore store,
IElasticClient elasticClient,
ElasticSearchOptionsSection options,
ILogger<Program> logger) =>

Check warning on line 22 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Admin Projections / build-image

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 22 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build ACM Api / build-image

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 22 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Public Projections / build-image

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 22 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Public Projections / build-image

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
StartRebuild(logger, projectionName: "Detail", rebuildFunc: async () =>
{
var projectionDaemon = await store.BuildProjectionDaemonAsync();
await projectionDaemon.RebuildProjection<PubliekVerenigingDetailProjection>(shardTimeout, CancellationToken.None);
});

StartRebuild(logger, projectionName: "Search", rebuildFunc: async () =>
{
var projectionDaemon = await store.BuildProjectionDaemonAsync();
await projectionDaemon.StopShard($"{ProjectionNames.VerenigingZoeken}:All");

await elasticClient.Indices.DeleteAsync(options.Indices.Verenigingen, ct: CancellationToken.None);

Check warning on line 35 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Admin Projections / build-image

Dereference of a possibly null reference.

Check warning on line 35 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build ACM Api / build-image

Dereference of a possibly null reference.

Check warning on line 35 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Public Projections / build-image

Dereference of a possibly null reference.

Check warning on line 35 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Public Projections / build-image

Dereference of a possibly null reference.
await elasticClient.Indices.CreateVerenigingIndexAsync(options.Indices.Verenigingen);

await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken, shardTimeout, CancellationToken.None);
await projectionDaemon.StartShard($"{ProjectionNames.VerenigingZoeken}:All", CancellationToken.None);
});

return Results.Accepted();
});

app.MapPost(
pattern: "v1/projections/detail/rebuild",
handler: async (IDocumentStore store, ILogger<Program> logger) =>

Check warning on line 47 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Admin Projections / build-image

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 47 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build ACM Api / build-image

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 47 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Public Projections / build-image

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 47 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Public Projections / build-image

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
StartRebuild(logger, projectionName: "Detail", rebuildFunc: async () =>
{
var projectionDaemon = await store.BuildProjectionDaemonAsync();
await projectionDaemon.RebuildProjection<PubliekVerenigingDetailProjection>(shardTimeout,CancellationToken.None);
await projectionDaemon.RebuildProjection<PubliekVerenigingDetailProjection>(shardTimeout, CancellationToken.None);
});

return Results.Accepted();
Expand All @@ -42,7 +71,7 @@ public static void AddProjectionEndpoints(this WebApplication app, RebuildConfig
await elasticClient.Indices.DeleteAsync(options.Indices.Verenigingen, ct: CancellationToken.None);

Check warning on line 71 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Admin Projections / build-image

Dereference of a possibly null reference.

Check warning on line 71 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build ACM Api / build-image

Dereference of a possibly null reference.

Check warning on line 71 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Public Projections / build-image

Dereference of a possibly null reference.

Check warning on line 71 in src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs

View workflow job for this annotation

GitHub Actions / Build Public Projections / build-image

Dereference of a possibly null reference.
await elasticClient.Indices.CreateVerenigingIndexAsync(options.Indices.Verenigingen);

await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken,shardTimeout, CancellationToken.None);
await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken, shardTimeout, CancellationToken.None);
await projectionDaemon.StartShard($"{ProjectionNames.VerenigingZoeken}:All", CancellationToken.None);
});

Expand Down

0 comments on commit 39c9eb2

Please sign in to comment.