private async Task <string> RenewExternalToken(Pex2AplosMappingModel mapping, CancellationToken cancellationToken) { if (mapping.GetLastRenewedDateUtc() < DateTime.UtcNow.AddMonths(-6)) { _log.LogWarning($"External API token is older than 6 months and could not be renewed for business: {mapping.PEXBusinessAcctId}"); return(mapping.PEXExternalAPIToken); } if (mapping.GetLastRenewedDateUtc() < DateTime.UtcNow.AddMonths(-5).AddDays(-1)) //Wait an extra day in case of timing issues (server time differences, DST complications, etc.) { _log.LogInformation($"Renewing external API token for business: {mapping.PEXBusinessAcctId}"); var response = await _pexApiClient.RenewExternalToken(mapping.PEXExternalAPIToken, cancellationToken); return(response.Token); } return(mapping.PEXExternalAPIToken); }