Exemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            // note that we don't want to call this on each loop iteration,
            // or we will create a backlog of waits that must be satisfied by the controller.
            // we only want one outstanding at any time
            var wait = _trigger.WaitAsync();

            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    var requests = await _requestStore.List(stoppingToken);

                    await Task.WhenAll(requests.Select(HandleRequest));
                }
                catch (Exception ex) when(!(ex is TaskCanceledException))
                {
                    _logger.LogError(ex, $"Unexpected error in {nameof(ScaleUpProcessorHost)} main loop");
                }

                var completed = await Task.WhenAny(Task.Delay(ResizeCheckDelay, stoppingToken), wait);

                if (completed == wait)
                {
                    // if our wait was completed we need to start a new one
                    wait = _trigger.WaitAsync();
                }
            }
        }