Exemple #1
0
        private async Task RefreshTokens(CancellationToken cancellationToken)
        {
            _log.LogInformation("Refreshing Tokens");
            var mappings = await _mappingStorage.GetAllMappings(cancellationToken);

            foreach (var mapping in mappings)
            {
                try
                {
                    var externalToken = await RenewExternalToken(mapping, cancellationToken);

                    if (!mapping.PEXExternalAPIToken.Equals(externalToken, StringComparison.InvariantCultureIgnoreCase))
                    {
                        mapping.PEXExternalAPIToken = externalToken;
                        mapping.LastRenewedUtc      = DateTime.UtcNow;
                        await _mappingStorage.UpdateAsync(mapping, cancellationToken);
                    }
                    if (!_inUseExternalApiTokens.Contains(mapping.PEXExternalAPIToken))
                    {
                        _inUseExternalApiTokens.Add(mapping.PEXExternalAPIToken);
                    }
                }
                catch (Exception ex)
                {
                    _log.LogError(ex,
                                  $"Exception during renew external token for business {mapping.PEXBusinessAcctId}. {ex}");
                }
            }
        }
Exemple #2
0
        public async Task Run([TimerTrigger("0 16 3 * * *")] TimerInfo myTimer, CancellationToken cancellationToken, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.UtcNow}");

            var mappings = await _mappingStorage.GetAllMappings(cancellationToken);

            log.LogInformation($"Found {mappings.Count()} mappings.");

            foreach (var mapping in mappings)
            {
                log.LogInformation($"Enqueuing {nameof(mapping.PEXBusinessAcctId)} '{mapping.PEXBusinessAcctId}'");
                await _mappingQueue.EnqueueMapping(mapping, cancellationToken);
            }

            log.LogInformation($"C# Timer trigger function finished at: {DateTime.UtcNow}");
        }