private async void ExecuteBatch(object state) { if (!_batchesToRun.TryDequeue(out Batch batch)) { BatchExecutionReset(); return; } _runningBatches.TryAdd(batch.Id, batch); try { var processorJobs = batch.Jobs.ToArray(); var jobs = processorJobs.Select(x => x.Job).ToArray(); var jobResults = await _batchProcessor.ProcessBatch(jobs); for (int i = 0; i < jobResults.Length - 1; i++) { processorJobs[i].FinishedWith(jobResults[i]); } _runningBatches.TryRemove(batch.Id, out batch); batch.TaskCompletionSource.SetResult(true); } catch (Exception e) { batch.TaskCompletionSource.SetException(e); } BatchExecutionReset(); }
/// <summary> /// Emits the current batch. /// </summary> /// <param name="batch">The batch.</param> private void ProcessBatch(ProcessorContext processorContext, string batch) { m_processor.ProcessProgress(processorContext, "Executing batch " + processorContext.CurrentBatchNo); Debug.WriteLineIf(GlobalSettings.Verbosity.TraceVerbose, batch); try { m_processor.ProcessBatch(processorContext, batch); } catch (Sqt.DbcProvider.WrappedDbException ex) { ++m_errorCount; string message = FormatError(processorContext, TraceLevel.Error, ex.Message, ex.LineNumber); Trace.WriteLineIf(GlobalSettings.Verbosity.TraceError, message); if (m_options.BreakOnError) { throw new TerminateException(ExitCode.SqlCommandError); } } catch (System.Data.SqlClient.SqlException ex) { ++m_errorCount; string message = FormatError(processorContext, TraceLevel.Error, ex.Message, ex.LineNumber); Trace.WriteLineIf(GlobalSettings.Verbosity.TraceError, message); if (m_options.BreakOnError) { throw new TerminateException(ExitCode.SqlCommandError); } } catch (System.Data.Common.DbException ex) { ++m_errorCount; string message = FormatError(processorContext, TraceLevel.Error, ex.Message, 0); Trace.WriteLineIf(GlobalSettings.Verbosity.TraceError, message); if (m_options.BreakOnError) { throw new TerminateException(ExitCode.SqlCommandError); } } }