public async Task TimedBatchBlock_Example() { // setup timed batch block var timedBatchBlock = new TimedBatchBlock <Customer>(new TimedBackBlockConfig()); timedBatchBlock.SetHandler(async customers => await PerformAction(customers, 1, 1)); List <Task> tasks = new List <Task>(); var bulkService = new BulkCustomerDataService(95); await foreach (var importCustomer in bulkService.GetCustomersFromImportAsync()) { // this is designed to be executed in many separate threads (using rebus typically) // if you await here it will wait the full 10 seconds for each message tasks.Add(timedBatchBlock.Queue(importCustomer.ToCustomer())); } // timed block will still have the last 5 records queued up waiting for more await Task.Delay(1000); Assert.AreEqual(9, _performActionCount, "Batch block should not be finished yet."); await Task.Delay(2000); Assert.AreEqual(10, _performActionCount, "Batch block should be done."); Task.WaitAll(tasks.ToArray()); }
/// <nodoc /> public VsoClient(IIpcLogger logger, DropDaemon dropDaemon) { Contract.Requires(dropDaemon?.DropConfig != null); m_logger = logger; m_dropDaemon = dropDaemon; m_config = dropDaemon.DropConfig; m_cancellationSource = new CancellationTokenSource(); logger.Info("Using drop config: " + JsonConvert.SerializeObject(m_config)); Stats = new DropStatistics(); // instantiate drop client m_dropClient = new ReloadingDropServiceClient( logger: logger, clientConstructor: CreateDropServiceClient); m_batchBlock = new TimedBatchBlock <AddFileItem>( maxDegreeOfParallelism: m_config.MaxParallelUploads, batchSize: m_config.BatchSize, nagleInterval: m_config.NagleTime, batchProcessor: ProcessAddFilesAsync); if (m_config.ArtifactLogName != null) { DropAppTraceSource.SingleInstance.SetSourceLevel(System.Diagnostics.SourceLevels.Verbose); Tracer.AddFileTraceListener(Path.Combine(m_config.LogDir, m_config.ArtifactLogName)); } }
/// <nodoc /> public VsoSymbolClient(IIpcLogger logger, SymbolConfig config, Client apiClient) { m_logger = logger; m_apiClient = apiClient; m_config = config; m_debugEntryCreateBehavior = config.DebugEntryCreateBehavior; m_cancellationSource = new CancellationTokenSource(); m_counters = new CounterCollection <SymbolClientCounter>(); m_logger.Info(I($"[{nameof(VsoSymbolClient)}] Using symbol config: {JsonConvert.SerializeObject(m_config)}")); m_symbolClient = new ReloadingSymbolClient( logger: logger, clientConstructor: CreateSymbolServiceClient); m_batchBlock = new TimedBatchBlock <BatchedSymbolFile>( maxDegreeOfParallelism: m_config.MaxParallelUploads, batchSize: m_config.BatchSize, nagleInterval: m_config.NagleTime, batchProcessor: ProcessBatchedFilesAsync); m_fileUploadQueue = new ActionQueue(m_config.MaxParallelUploads); }