This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async Task<HttpResponseMessage> callAPI() | |
| { | |
| Logger.LogThreadInfo($"Calling API for message " + | |
| $"{consumeResult.Message.Key}"); | |
| var json = new StringContent( | |
| consumeResult.Message.Value, Encoding.UTF8, | |
| "application/json"); | |
| var client = _httpClientFactory.CreateClient(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Worker : BackgroundService | |
| { | |
| public IServiceProvider Services { get; } | |
| private readonly ILogger<Worker> _logger; | |
| public Worker( | |
| IServiceProvider services, | |
| ILogger<Worker> logger) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Custody of Microsoft - DO NOT USE */ | |
| //ConfigureServices() - Startup.cs | |
| services.AddHttpClient<IBasketService, BasketService>() | |
| //Set lifetime to five minutes | |
| .SetHandlerLifetime(TimeSpan.FromMinutes(5)) | |
| .AddPolicyHandler(GetRetryPolicy()); | |
| // 2 ^ 1 = 2 seconds then | |
| // 2 ^ 2 = 4 seconds then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Produce<T>( | |
| string msgKey, T msgVal, string topic = "retry-transient-error") | |
| { | |
| Logger.LogThreadInfo("Produce() method"); | |
| using var producer = new ProducerBuilder<string, string>(config).Build(); | |
| var val = JsonConvert.SerializeObject(msgVal); | |
| Logger.LogInfo($"Producing record: {val}"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // API Controller | |
| [HttpPost] | |
| public async Task<bool> AgreeToRetry( | |
| [FromBody] IEnumerable<GitHubBranch> gitHubBranches) | |
| { | |
| Logger.LogThreadInfo("Controller AgreeToRetry()"); | |
| return await yoyo.AgreeToRetry(gitHubBranches); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task<IList<RuleResult>> ParallelAll( | |
| List<Func<T, Task<RuleResult>>> parallelAsyncRules, T ruleCtx) | |
| { | |
| if (parallelAsyncRules?.Count < 1) | |
| { | |
| return null; | |
| } | |
| var tasks = parallelAsyncRules.Select(r => r(ruleCtx)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task<RuleResult> FirstFails( | |
| IList<Func<T, Task<RuleResult>>> sequentialAsyncRules, T ruleCtx) | |
| { | |
| if (sequentialAsyncRules?.Count < 1) | |
| { | |
| return null; | |
| } | |
| RuleResult firstFailed = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public IEnumerable<RuleResult> All( | |
| IList<Func<T, RuleResult>> sequentialRules, T ruleCtx) | |
| => sequentialRules?.Select(r => r(ruleCtx)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public TSideEffect Pick<TSideEffect>() where TSideEffect: class | |
| { | |
| if (SideEffect.Count == 0) | |
| { | |
| return null; | |
| } | |
| if (SideEffect.TryGetValue(typeof(TSideEffect), out object value)) | |
| { | |
| return (TSideEffect)value; |