示例#1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            if (!await _queue.Ensure(stoppingToken).ConfigureAwait(false))
            {
                _logger.LogError("Couldn't ensure that Queue is there.");
                return;
            }

            if (!await _database.Verify(stoppingToken).ConfigureAwait(true))
            {
                _logger.LogError("Couldn't verify database connection.");
                return;
            }

            while (!stoppingToken.IsCancellationRequested)
            {
                var changes = _database.GetChanges(stoppingToken).ConfigureAwait(false);

                await foreach (var change in changes.WithCancellation(stoppingToken))
                {
                    _logger.LogInformation("Create Message for Entity ID: {entityId} Mutation ID {mutationId}", change.EntityId, change.MutationId);
                    await _queue.AddMessage(change, stoppingToken).ConfigureAwait(false);
                }

                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                await Task.Delay(500, stoppingToken).ConfigureAwait(false);
            }
        }