Exemplo n.º 1
0
        /// <summary>
        /// Initialize a new instance of the <see cref="DataflowWebHookSender"/> with the given retry policy, <paramref name="options"/>,
        /// and <paramref name="httpClient"/>. This constructor is intended for unit testing purposes.
        /// </summary>
        internal DataflowWebHookSender(IWebhookPolicyContainer policyContainer, ILogger <DataflowWebHookSender> logger, IEnumerable <TimeSpan> retryDelays, ExecutionDataflowBlockOptions options, HttpClient httpClient, IOptions <WebHookSettings> settings)
            : base(logger, settings)
        {
            _policyContainer = policyContainer ?? throw new ArgumentNullException(nameof(policyContainer));
            retryDelays      = retryDelays ?? DefaultRetries;

            options = options ?? new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = DefaultMaxConcurrencyLevel
            };

            _httpClient = httpClient ?? new HttpClient();

            // Create the launch processors with the given retry delays
            _launchers = new ActionBlock <WebHookWorkItem> [1 + retryDelays.Count()];

            _buffer = new BufferBlock <WebHookWorkItem>();
            var offset = 0;

            _launchers[offset++] = new ActionBlock <WebHookWorkItem>(async item => await LaunchWebHook(item), options);
            foreach (var delay in retryDelays)
            {
                _launchers[offset++] = new ActionBlock <WebHookWorkItem>(async item => await DelayedLaunchWebHook(item, delay), options);
            }
            _buffer.LinkTo(_launchers[0], new DataflowLinkOptions()
            {
                PropagateCompletion = true
            });

            var message = string.Format(CultureInfo.CurrentCulture, CustomResources.Manager_Started, typeof(DataflowWebHookSender).Name, _launchers.Length);

            Logger.LogInformation(message);
        }
 public WebhookPolicyContainerCleanupService(IWebhookPolicyContainer policyContainers, IServiceProvider serviceProvider, ILogger <WebhookPolicyContainerCleanupService> logger)
 {
     _policyContainers = policyContainers;
     _serviceProvider  = serviceProvider;
     _logger           = logger;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataflowWebHookSender"/> class with a default retry policy.
 /// </summary>
 /// <param name="logger">The current <see cref="ILogger"/>.</param>
 /// <param name="settings">The current <see cref="WebHookSettings"/>.</param>
 public DataflowWebHookSender(IWebhookPolicyContainer policyContainer, ILogger <DataflowWebHookSender> logger, IOptions <WebHookSettings> settings)
     : this(policyContainer, logger, retryDelays : null, options : null, httpClient : null, settings : settings)
 {
 }