예제 #1
0
        /// <inheritdoc/>
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            try
            {
                await _fhirService.CheckFhirServiceCapability(cancellationToken);

                LogWorkerStartingDelegate(_logger, null);

                while (!cancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        await _changeFeedProcessor.ProcessAsync(_dicomCastWorkerConfiguration.PollIntervalDuringCatchup, cancellationToken);

                        await Task.Delay(_dicomCastWorkerConfiguration.PollInterval, cancellationToken);
                    }
                    catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested)
                    {
                        // Cancel requested.
                        LogWorkerCancelRequestedDelegate(_logger, null);
                        break;
                    }
                }

                LogWorkerExitingDelegate(_logger, null);
            }
            catch (Exception ex)
            {
                LogUnhandledExceptionDelegate(_logger, ex);

                // Any exception in ExecuteAsync will not shutdown application, call hostApplicationLifetime.StopApplication() to force shutdown.
                // Please refer to .net core issue on github for more details: "Exceptions in BackgroundService ExecuteAsync are (sometimes) hidden" https://github.com/dotnet/extensions/issues/2363
                _hostApplicationLifetime.StopApplication();
            }
        }