private async Task Subscribe <TContext>(IConnectedProjection <TContext> projection) where TContext : RunnerDbContext <TContext> { if (projection == null || _registeredProjections.IsProjecting(projection.Name)) { return; } long?projectionPosition; using (var context = projection.ContextFactory()) projectionPosition = await context.Value.GetRunnerPositionAsync(projection.Name, CancellationToken.None); if ((projectionPosition ?? -1) >= (_lastProcessedMessagePosition ?? -1)) { _logger.LogInformation( "Subscribing {ProjectionName} at {ProjectionPosition} to AllStream at {StreamPosition}", projection.Name, projectionPosition, _lastProcessedMessagePosition); _handlers.Add( projection.Name, async(message, token) => await projection.ConnectedProjectionMessageHandler.HandleAsync(message, token)); } else { _commandBus.Queue(new StartCatchUp(projection.Name)); } }
private void Start <TContext>(IConnectedProjection <TContext>?projection) where TContext : RunnerDbContext <TContext> { if (projection == null || _registeredProjections.IsProjecting(projection.Id)) { return; } _projectionCatchUps.Add(projection.Id, new CancellationTokenSource()); var projectionCatchUp = projection.CreateCatchUp( _streamStore, _commandBus, _catchUpStreamGapStrategy, _logger); TaskRunner.Dispatch(async() => await projectionCatchUp.CatchUpAsync(_projectionCatchUps[projection.Id].Token)); }
private void Start <TContext>(IConnectedProjection <TContext> projection) where TContext : RunnerDbContext <TContext> { if (projection == null || _registeredProjections.IsProjecting(projection.Name)) { return; } _projectionCatchUps.Add(projection.Name, new CancellationTokenSource()); var projectionCatchUp = new ConnectedProjectionCatchUp <TContext>( projection.Name, _streamStore, projection.ContextFactory, projection.ConnectedProjectionMessageHandler, _commandBus, _logger); TaskRunner.Dispatch(async() => await projectionCatchUp.CatchUpAsync(_projectionCatchUps[projection.Name].Token)); }