feat: complete end to end functionality
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user