public async Task Add(InferenceRequest inferenceRequest) { Guard.Against.Null(inferenceRequest, nameof(inferenceRequest)); using var loggerScope = _logger.BeginScope(new LogginDataDictionary <string, object> { { "JobId", inferenceRequest.JobId }, { "TransactionId", inferenceRequest.TransactionId } }); await Policy .Handle <Exception>() .WaitAndRetryAsync( 3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (exception, timeSpan, retryCount, context) => { _logger.Log(LogLevel.Error, exception, $"Error saving inference request. Waiting {timeSpan} before next retry. Retry attempt {retryCount}."); }) .ExecuteAsync(async() => { await _inferenceRequestRepository.AddAsync(inferenceRequest); await _inferenceRequestRepository.SaveChangesAsync(); _inferenceRequestRepository.Detach(inferenceRequest); _logger.Log(LogLevel.Debug, $"Inference request saved."); }) .ConfigureAwait(false); }
/// <summary> /// Adds a new job to the queue (database). A copy of the payload is made to support multiple pipelines per AE Title. /// </summary> /// <param name="job">Job to be queued.</param> /// <param name="enableTracking">Indicates if change tracking should be enabled with Entity Framework.</param> public async Task Add(InferenceJob job, bool enableTracking) { Guard.Against.Null(job, nameof(job)); using (_logger.BeginScope(new LogginDataDictionary <string, object> { { "JobId", job.JobId }, { "PayloadId", job.PayloadId } })) { ConfigureStoragePath(job); // Makes a copy of the payload to support multiple pipelines per AE Title. // Future, consider use of persisted payloads. MakeACopyOfPayload(job); await Policy .Handle <Exception>() .WaitAndRetryAsync( 3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (exception, timeSpan, retryCount, context) => { _logger.Log(LogLevel.Error, exception, $"Error saving inference job. Waiting {timeSpan} before next retry. Retry attempt {retryCount}."); }) .ExecuteAsync(async() => { await _inferenceJobRepository.AddAsync(job); await _inferenceJobRepository.SaveChangesAsync(); if (!enableTracking) { _inferenceJobRepository.Detach(job); } }) .ConfigureAwait(false); } }