public async Task ExecuteBatch(ProjectionUpdateBatch batch) { await batch.Queue.Completion; using (var session = (DocumentSessionBase)_store.LightweightSession()) { try { await session.ExecuteBatchAsync(batch, _cancellationSource.Token); _logger.LogInformation($"Shard '{ProjectionOrShardName}': Executed updates for {batch.Range}"); } catch (Exception e) { _logger.LogError(e, $"Failure in shard '{ProjectionOrShardName}' trying to execute an update batch for {batch.Range}"); // TODO -- error handling throw; } } batch.Dispose(); Position = batch.Range.SequenceCeiling; _tracker.Publish(new ShardState(ProjectionOrShardName, batch.Range.SequenceCeiling)); _commandBlock.Post(Command.Completed(batch.Range)); }
public async Task Stop(Exception ex = null) { _logger.LogInformation("Stopping projection shard '{ShardName}'", _projectionShard.Name); _cancellationSource?.Cancel(); _commandBlock.Complete(); await _commandBlock.Completion; _loader.Complete(); await _loader.Completion; _hopper.Complete(); await _hopper.Completion; try { await _projectionShard.Stop(); } catch (Exception e) { _logger.LogError(e, "Error trying to stop shard '{ShardName}'", _projectionShard.Name); } _subscription.Dispose(); _fetcher.Dispose(); _subscription = null; _fetcher = null; _commandBlock = null; _hopper = null; _loader = null; _logger.LogInformation("Stopped projection shard '{ShardName}'", _projectionShard.Name); _tracker.Publish(new ShardState(_projectionShard.Name, Position) { Action = ShardAction.Stopped, Exception = null }); }
public Task Stop(Exception ex = null) { _isStopping = true; _logger.LogInformation("Stopping projection shard '{ShardName}'", _projectionShard.Name); _cancellationSource?.Cancel(); _commandBlock.Complete(); _loader.Complete(); _grouping.Complete(); _building.Complete(); _subscription.Dispose(); _fetcher.Dispose(); _subscription = null; _fetcher = null; _commandBlock = null; _grouping = null; _loader = null; _building = null; _logger.LogInformation("Stopped projection shard '{ShardName}'", _projectionShard.Name); _tracker.Publish(new ShardState(_projectionShard.Name, Position) { Action = ShardAction.Stopped, Exception = ex }); _isStopping = false; return Task.CompletedTask; }