private void ProcessChunk() { var fileReader = fileReaderFactory.Create(jobContext.Operation == Operation.Decompress); try { foreach (var chunk in fileReader.Read(fileInfo)) { var local = chunk; local.JobBatchItemId = batchItemId; queue.Add(local); jobContext.SubmittedId = batchItemId; Interlocked.Increment(ref batchItemId); } } catch (IOException e) { jobContext.Failure(e, e.Message); cancellationTokenSource.Cancel(); } finally { countdown.Signal(); } queue.CompleteAdding(); }
private void SaveProcessedChunks() { try { using var file = fileWriter.OpenFile(fileInfo, jobContext.Operation == Operation.Decompress); foreach (var processedBatchItem in processedJobQueue.GetConsumingEnumerable()) { if (!cancellationToken.IsCancellationRequested) { jobContext.ProcessedId = processedBatchItem.JobBatchItemId; file.Write(processedBatchItem.Processed.Memory.Span); processedBatchItem.Processed.ReturnBuffer(); } else { break; } } } catch (Exception e) { jobContext.Failure(e, e.Message); cancellationTokenSource.Cancel(); } finally { countdown.Signal(); } }
private void ProcessChunk() { try { foreach (var jobBatchItem in jobQueue.GetConsumingEnumerable()) { if (cancellationToken.IsCancellationRequested) { break; } var processed = new ProcessedBatchItem { JobBatchItemId = jobBatchItem.JobBatchItemId, Processed = byteProcessor.Process(jobBatchItem.Memory) }; jobBatchItem.ReleaseBuffer(); if (!cancellationToken.IsCancellationRequested) { outputBuffer.SubmitProcessedBatchItem(processed); } } } catch (Exception e) { jobContext.Failure(e, e.Message); cancellationTokenSource.Cancel(); } finally { countdown.Signal(); } outputBuffer.SubmitCompleted(); }