/* * Info from EFGS team: * EFGS will never change a existing batch. * Batching process is triggered all 5 minutes. And then the batching searches all uploaded keys of the last 5 minutes. And these keys will be put into a new batch * */ public void DownloadKeysFromGateway(int forLastNumberOfDays) { var lastDownloadState = _settingsService.GetGatewayDownloadState(); string lastSyncedBatchTag = lastDownloadState.LastSyncedBatchTag; var lastSyncDateTicks = lastDownloadState.LastSyncDate; var lastSyncDate = lastSyncDateTicks.HasValue ? new DateTime(lastSyncDateTicks.Value, DateTimeKind.Utc) : DateTime.UnixEpoch; DateTime todayDate = DateTime.UtcNow.Date; // It there hasn't been sync for more than {maximumNumberOfDaysBack} change date to the oldest possible and reset the batchTag DateTime oldestDatePossible = todayDate.AddDays(-forLastNumberOfDays + 1); var startDate = lastSyncDate < oldestDatePossible ? oldestDatePossible : lastSyncDate; if (startDate != lastSyncDate) { lastSyncedBatchTag = null; // date has changed BatchTag need to be reset _logger.LogWarning($"CHECK IF DOWNLOAD IS CALLED PERIODICALLY. Last Download has been at {lastSyncDate.Date}." + $" The gateway have history only for last {forLastNumberOfDays} days (from <{oldestDatePossible},{todayDate}>)."); } var currentDownloadDate = startDate; while (currentDownloadDate <= todayDate) { var lastProcessedBatchTag = DownloadKeysFromGatewayFromGivenDate(currentDownloadDate, lastSyncedBatchTag); //save lastProcessedBatchTag var currentState = new GatewayDownloadState() { LastSyncDate = currentDownloadDate.Ticks, LastSyncedBatchTag = lastProcessedBatchTag }; _settingsService.SaveGatewaySyncState(currentState); currentDownloadDate = currentDownloadDate.AddDays(1); lastSyncedBatchTag = null; } }
public void Save(GatewayDownloadState lastSyncState) { var jsonString = JsonSerializer.Serialize(lastSyncState); SetProperty(Keys.DownloadState, jsonString); }
public GatewayDownloadState GetDownloadState() { GatewayDownloadState syncStatusDto = GetStateOrNull <GatewayDownloadState>(Keys.DownloadState); return(syncStatusDto ?? new GatewayDownloadState()); }
public void SaveGatewaySyncState(GatewayDownloadState lastSyncState) { ModelValidator.ValidateContract(lastSyncState); _syncStateDao.Save(lastSyncState); }