void IBaseProcess.HandleVolume(IVolumeHandler handler, IProcessExecutionContextWithVolume processContext, CancellationToken cancellationToken) { var volumeGenerated = processContext.ProcessState.IsVolumeGenerated; if (!volumeGenerated || CanRegenerateVolume) { var volume = GetVolume(processContext); if (volume != null) { handler.Handle(volume, processContext, cancellationToken); //volume visitor } } }
public void Handle <T>(IEnumerable <T> volume, IProcessExecutionContextWithVolume processContext, CancellationToken token) { if (volume == null) { processContext.Logger.Info("No volume returned"); return; } bool hasVolume = false; var serializer = _serializersFactory.GetSerializer <T>(); int currentCount = 0; int batchSize = 100; try { Bus.HandleDbCommand(new DbAction(DbActions.Transaction, () => //create transaction in Db Bus pipeline { var volumeDeletedCount = ExecuteNonQuery(Constant.SQLDeleteProcessVolume, processContext.ProcessState.Id); if (volumeDeletedCount > 0) { processContext.Logger.Warn($"Existing volume {volumeDeletedCount} deleting"); } })); //using (var unitOfWork = ) //IsolationLevel.Snapshot //todo check isolation level with db team, is it enabled by default { foreach (var v in volume) { var payLoad = serializer.SerializeToString(v); IReadWritableTaskState state = CreateNew(); state.Payload = payLoad; state.ProcessId = processContext.ProcessState.Id; state.CurrentState = ResultStatus.Empty.Name; currentCount++; if (currentCount >= batchSize) { token.ThrowIfCancellationRequested(); hasVolume = true; //Persist(); currentCount = 0; //Clear();//remove persisted items } } //if (Entity.Count>0) { token.ThrowIfCancellationRequested(); hasVolume = true; // Persist(); } //Commit(); } } finally { //dispose / rollback } if (hasVolume) { processContext.SetVolumeGenerated(); } }