feat: complete end to end functionality

This commit is contained in:
Stevan Freeborn
2024-09-01 18:09:48 -05:00
parent 78748cc104
commit e400be31f7
19 changed files with 376 additions and 454 deletions
@@ -42,10 +42,62 @@ public class OnspringWorker(
GC.SuppressFinalize(this);
}
private Task RunSearchRequests()
private async Task RunSearchRequests()
{
var searchBatchIdProperty = LogContext.PushProperty("SearchBatchId", Guid.NewGuid());
_logger.LogInformation("Running search requests");
return Task.CompletedTask;
try
{
using var scope = _serviceScopeFactory.CreateAsyncScope();
var onspringService = scope.ServiceProvider.GetRequiredService<IOnspringService>();
var searchService = scope.ServiceProvider.GetRequiredService<ISearchService>();
var searchRequests = await onspringService.GetSearchRequestsAsync();
if (searchRequests.Count is 0)
{
_logger.LogInformation("No search requests found");
return;
}
foreach (var searchRequest in searchRequests)
{
var searchBatchItemIdProperty = LogContext.PushProperty("SearchBatchItemId", Guid.NewGuid());
try
{
_logger.LogInformation("Processing search request {SearchRequestId}", searchRequest.Id);
await onspringService.UpdateSearchRequestAsProcessingAsync(searchRequest);
var searchResult = await searchService.PerformSearchAsync(searchRequest);
await onspringService.AddSearchResultAsync(searchResult);
_logger.LogInformation("Search request {SearchRequestId} processed", searchRequest.Id);
}
catch (Exception ex)
{
await onspringService.UpdateSearchRequestAsFailedAsync(
searchRequest,
$"Failed to process search request: {ex.Message}"
);
_logger.LogError(ex, "Failed to process search request {SearchRequestId}", searchRequest.Id);
}
finally
{
searchBatchItemIdProperty.Dispose();
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to run search requests");
}
finally
{
searchBatchIdProperty.Dispose();
}
}
}