@Test public void shouldCallDownloader() { testee.historyCheckEnabled = true; testee.lastDownload = Instant.now(); List<FileDownloadStatus> statuses = Collections.singletonList(FileDownloadStatus.REQUESTED); List<FileDownloadEntity> downloadsWaitingForUpdate = Collections.singletonList(new FileDownloadEntity()); when(downloadRepository.findByStatusInAndTimeAfterOrderByTimeDesc(eq(statuses), any())).thenReturn(downloadsWaitingForUpdate); List<FileDownloadEntity> downloadsReturnedFromDownloader = Collections.singletonList(new FileDownloadEntity()); when(downloaderMock.checkForStatusUpdates(any(),eq(StatusCheckType.HISTORY))).thenReturn(downloadsReturnedFromDownloader); testee.checkStatus(statuses, 10000, StatusCheckType.HISTORY); verify(downloaderMock).checkForStatusUpdates(downloadsWaitingForUpdate, StatusCheckType.HISTORY); verify(downloadRepository).saveAll(downloadsReturnedFromDownloader); }
protected void checkStatus(List<FileDownloadStatus> nzbDownloadStatuses, long maxAgeDownloadEntitiesInSeconds, StatusCheckType statusCheckType) { if ((!queueCheckEnabled && statusCheckType == StatusCheckType.QUEUE) || (!historyCheckEnabled && statusCheckType == StatusCheckType.HISTORY)) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because it's disabled", statusCheckType); return; } if (lastDownload.isBefore(Instant.now().minusSeconds(MIN_SECONDS_SINCE_LAST_DOWNLOAD_TO_CHECK_STATUSES))) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because last download was {}", statusCheckType, lastDownload); return; } List<FileDownloadEntity> downloadsWaitingForUpdate = downloadRepository.findByStatusInAndTimeAfterOrderByTimeDesc(nzbDownloadStatuses, Instant.now().minusSeconds(maxAgeDownloadEntitiesInSeconds)); if (downloadsWaitingForUpdate.isEmpty()) { if (statusCheckType == StatusCheckType.QUEUE) { queueCheckEnabled = false; } else { historyCheckEnabled = false; } logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Returning and setting {} status update disabled because no current downloads are waiting for updates", statusCheckType); return; } List<FileDownloadEntity> updatedDownloads = new ArrayList<>(); logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "{} downloads waiting for {} update", downloadsWaitingForUpdate.size(), statusCheckType); for (Downloader downloader : downloaderProvider.getAllDownloaders()) { if (downloader.isEnabled()) { updatedDownloads.addAll(downloader.checkForStatusUpdates(downloadsWaitingForUpdate, statusCheckType)); } } downloadRepository.saveAll(updatedDownloads); }
DownloadStatusUpdater { protected void checkStatus(List<FileDownloadStatus> nzbDownloadStatuses, long maxAgeDownloadEntitiesInSeconds, StatusCheckType statusCheckType) { if ((!queueCheckEnabled && statusCheckType == StatusCheckType.QUEUE) || (!historyCheckEnabled && statusCheckType == StatusCheckType.HISTORY)) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because it's disabled", statusCheckType); return; } if (lastDownload.isBefore(Instant.now().minusSeconds(MIN_SECONDS_SINCE_LAST_DOWNLOAD_TO_CHECK_STATUSES))) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because last download was {}", statusCheckType, lastDownload); return; } List<FileDownloadEntity> downloadsWaitingForUpdate = downloadRepository.findByStatusInAndTimeAfterOrderByTimeDesc(nzbDownloadStatuses, Instant.now().minusSeconds(maxAgeDownloadEntitiesInSeconds)); if (downloadsWaitingForUpdate.isEmpty()) { if (statusCheckType == StatusCheckType.QUEUE) { queueCheckEnabled = false; } else { historyCheckEnabled = false; } logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Returning and setting {} status update disabled because no current downloads are waiting for updates", statusCheckType); return; } List<FileDownloadEntity> updatedDownloads = new ArrayList<>(); logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "{} downloads waiting for {} update", downloadsWaitingForUpdate.size(), statusCheckType); for (Downloader downloader : downloaderProvider.getAllDownloaders()) { if (downloader.isEnabled()) { updatedDownloads.addAll(downloader.checkForStatusUpdates(downloadsWaitingForUpdate, statusCheckType)); } } downloadRepository.saveAll(updatedDownloads); } }
DownloadStatusUpdater { protected void checkStatus(List<FileDownloadStatus> nzbDownloadStatuses, long maxAgeDownloadEntitiesInSeconds, StatusCheckType statusCheckType) { if ((!queueCheckEnabled && statusCheckType == StatusCheckType.QUEUE) || (!historyCheckEnabled && statusCheckType == StatusCheckType.HISTORY)) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because it's disabled", statusCheckType); return; } if (lastDownload.isBefore(Instant.now().minusSeconds(MIN_SECONDS_SINCE_LAST_DOWNLOAD_TO_CHECK_STATUSES))) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because last download was {}", statusCheckType, lastDownload); return; } List<FileDownloadEntity> downloadsWaitingForUpdate = downloadRepository.findByStatusInAndTimeAfterOrderByTimeDesc(nzbDownloadStatuses, Instant.now().minusSeconds(maxAgeDownloadEntitiesInSeconds)); if (downloadsWaitingForUpdate.isEmpty()) { if (statusCheckType == StatusCheckType.QUEUE) { queueCheckEnabled = false; } else { historyCheckEnabled = false; } logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Returning and setting {} status update disabled because no current downloads are waiting for updates", statusCheckType); return; } List<FileDownloadEntity> updatedDownloads = new ArrayList<>(); logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "{} downloads waiting for {} update", downloadsWaitingForUpdate.size(), statusCheckType); for (Downloader downloader : downloaderProvider.getAllDownloaders()) { if (downloader.isEnabled()) { updatedDownloads.addAll(downloader.checkForStatusUpdates(downloadsWaitingForUpdate, statusCheckType)); } } downloadRepository.saveAll(updatedDownloads); }  }
DownloadStatusUpdater { protected void checkStatus(List<FileDownloadStatus> nzbDownloadStatuses, long maxAgeDownloadEntitiesInSeconds, StatusCheckType statusCheckType) { if ((!queueCheckEnabled && statusCheckType == StatusCheckType.QUEUE) || (!historyCheckEnabled && statusCheckType == StatusCheckType.HISTORY)) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because it's disabled", statusCheckType); return; } if (lastDownload.isBefore(Instant.now().minusSeconds(MIN_SECONDS_SINCE_LAST_DOWNLOAD_TO_CHECK_STATUSES))) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because last download was {}", statusCheckType, lastDownload); return; } List<FileDownloadEntity> downloadsWaitingForUpdate = downloadRepository.findByStatusInAndTimeAfterOrderByTimeDesc(nzbDownloadStatuses, Instant.now().minusSeconds(maxAgeDownloadEntitiesInSeconds)); if (downloadsWaitingForUpdate.isEmpty()) { if (statusCheckType == StatusCheckType.QUEUE) { queueCheckEnabled = false; } else { historyCheckEnabled = false; } logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Returning and setting {} status update disabled because no current downloads are waiting for updates", statusCheckType); return; } List<FileDownloadEntity> updatedDownloads = new ArrayList<>(); logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "{} downloads waiting for {} update", downloadsWaitingForUpdate.size(), statusCheckType); for (Downloader downloader : downloaderProvider.getAllDownloaders()) { if (downloader.isEnabled()) { updatedDownloads.addAll(downloader.checkForStatusUpdates(downloadsWaitingForUpdate, statusCheckType)); } } downloadRepository.saveAll(updatedDownloads); }  @HydraTask(configId = "downloadHistoryCheck", name = "Download history check", interval = TEN_MINUTES_MS) @Transactional void checkHistoryStatus(); @HydraTask(configId = "downloadQueueCheck", name = "Download queue check", interval = TEN_SECONDS_MS) @Transactional void checkQueueStatus(); @EventListener void onNzbDownloadEvent(FileDownloadEvent downloadEvent); }
DownloadStatusUpdater { protected void checkStatus(List<FileDownloadStatus> nzbDownloadStatuses, long maxAgeDownloadEntitiesInSeconds, StatusCheckType statusCheckType) { if ((!queueCheckEnabled && statusCheckType == StatusCheckType.QUEUE) || (!historyCheckEnabled && statusCheckType == StatusCheckType.HISTORY)) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because it's disabled", statusCheckType); return; } if (lastDownload.isBefore(Instant.now().minusSeconds(MIN_SECONDS_SINCE_LAST_DOWNLOAD_TO_CHECK_STATUSES))) { logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Not executing {} status update because last download was {}", statusCheckType, lastDownload); return; } List<FileDownloadEntity> downloadsWaitingForUpdate = downloadRepository.findByStatusInAndTimeAfterOrderByTimeDesc(nzbDownloadStatuses, Instant.now().minusSeconds(maxAgeDownloadEntitiesInSeconds)); if (downloadsWaitingForUpdate.isEmpty()) { if (statusCheckType == StatusCheckType.QUEUE) { queueCheckEnabled = false; } else { historyCheckEnabled = false; } logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "Returning and setting {} status update disabled because no current downloads are waiting for updates", statusCheckType); return; } List<FileDownloadEntity> updatedDownloads = new ArrayList<>(); logger.debug(LoggingMarkers.DOWNLOAD_STATUS_UPDATE, "{} downloads waiting for {} update", downloadsWaitingForUpdate.size(), statusCheckType); for (Downloader downloader : downloaderProvider.getAllDownloaders()) { if (downloader.isEnabled()) { updatedDownloads.addAll(downloader.checkForStatusUpdates(downloadsWaitingForUpdate, statusCheckType)); } } downloadRepository.saveAll(updatedDownloads); }  @HydraTask(configId = "downloadHistoryCheck", name = "Download history check", interval = TEN_MINUTES_MS) @Transactional void checkHistoryStatus(); @HydraTask(configId = "downloadQueueCheck", name = "Download queue check", interval = TEN_SECONDS_MS) @Transactional void checkQueueStatus(); @EventListener void onNzbDownloadEvent(FileDownloadEvent downloadEvent);  }