private async Task <Establishment> GetEstablishmentFromCacheAsync(string id, DateTime?pointInTime, CancellationToken cancellationToken) { if (!int.TryParse(id, out var urn)) { throw new ArgumentException($"id must be a number (urn) but received {id}", nameof(id)); } var establishment = await _establishmentRepository.GetEstablishmentAsync(urn, pointInTime, cancellationToken); return(establishment); }
private async Task ProcessEstablishmentsAsync( long[] urns, DateTime pointInTime, bool managementGroupHasChanged, CancellationToken cancellationToken) { foreach (var urn in urns) { var previous = await _establishmentRepository.GetEstablishmentAsync(urn, pointInTime, cancellationToken); var staging = await _establishmentRepository.GetEstablishmentFromStagingAsync(urn, pointInTime, cancellationToken); if (previous == null) { _logger.Info($"Establishment {urn} has not been seen before {pointInTime}. Processing as created"); await StoreEstablishmentAndRaiseEventAsync(staging, false, cancellationToken); } else if (managementGroupHasChanged) { _logger.Info($"Management group of establishment {urn} on {pointInTime} has changed. Processing as updated"); await StoreEstablishmentAndRaiseEventAsync(staging, true, cancellationToken); } else if (!AreSame(previous, staging)) { _logger.Info($"Establishment {urn} on {pointInTime} has changed since {previous.PointInTime}. Processing as updated"); await StoreEstablishmentAndRaiseEventAsync(staging, true, cancellationToken); } else { _logger.Info($"Establishment {urn} on {pointInTime} has not changed since {previous.PointInTime}. Skipping"); } } }