1
0
Fork 0

sonarr series refresh

This commit is contained in:
Xavier Fontanet 2024-05-25 18:33:59 +02:00
parent 616a6faefd
commit d5f696dce4
3 changed files with 36 additions and 1 deletions

View File

@ -25,7 +25,7 @@ class FileCopier {
private void createDestinationFolderIfApply(Path destinationFile) throws IOException { private void createDestinationFolderIfApply(Path destinationFile) throws IOException {
var destinationFolder = destinationFile.getParent(); var destinationFolder = destinationFile.getParent();
if (isTemporaryDestination(destinationFolder) && !Files.exists(destinationFolder)) { if (isTemporaryDestination(destinationFolder) && !Files.exists(destinationFolder)) {
System.out.printf("destination folder %s will be created", destinationFolder); System.out.printf("destination folder %s will be created%n", destinationFolder);
if (!ConfigLoader.isTestMode()) if (!ConfigLoader.isTestMode())
Files.createDirectories(destinationFile); Files.createDirectories(destinationFile);
} }

View File

@ -9,6 +9,8 @@ import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class QueueFixer { public class QueueFixer {
final static String IMPORT_FAILURE_BECAUSE_MATCHED_BY_ID = "Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible. See the FAQ for details."; final static String IMPORT_FAILURE_BECAUSE_MATCHED_BY_ID = "Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible. See the FAQ for details.";
@ -16,9 +18,12 @@ public class QueueFixer {
private final SonarrApiGateway sonarrApiGateway; private final SonarrApiGateway sonarrApiGateway;
private final FailedImportFixer.Factory fixerFactory; private final FailedImportFixer.Factory fixerFactory;
private final SonarrDeferredRefresher sonarrDeferredRefresher;
QueueFixer(SonarrApiGateway sonarGateway) { QueueFixer(SonarrApiGateway sonarGateway) {
sonarrApiGateway = sonarGateway; sonarrApiGateway = sonarGateway;
fixerFactory = FailedImportFixer.factory(); fixerFactory = FailedImportFixer.factory();
sonarrDeferredRefresher = new SonarrDeferredRefresher();
} }
void fix() { void fix() {
@ -27,6 +32,7 @@ public class QueueFixer {
var recordsToFix = filterFailedImportsOfIdProblem(distinctRecords); var recordsToFix = filterFailedImportsOfIdProblem(distinctRecords);
recordsToFix.forEach(this::try2FixFailedImport); recordsToFix.forEach(this::try2FixFailedImport);
cleanWorkedElementsFromQueue(sonarQueue, recordsToFix); cleanWorkedElementsFromQueue(sonarQueue, recordsToFix);
refreshSeries(recordsToFix);
} }
private List<Record> retrieveQueueRecordsFromSonarr() { private List<Record> retrieveQueueRecordsFromSonarr() {
@ -87,4 +93,11 @@ public class QueueFixer {
.map(Record::getId) .map(Record::getId)
.toList(); .toList();
} }
private void refreshSeries(List<Record> recordsToFix) {
Set<Integer> seriesToRefresh = recordsToFix.stream()
.map(Record::getSeriesId)
.collect(Collectors.toSet());
sonarrDeferredRefresher.refreshSeries(seriesToRefresh);
}
} }

View File

@ -0,0 +1,22 @@
package tv.mangrana.worker;
import tv.mangrana.config.ConfigLoader;
import tv.mangrana.sonarr.Sonarr;
import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class SonarrDeferredRefresher {
private static final ScheduledExecutorService deferredRefresher = new ScheduledThreadPoolExecutor(1);
private final SonarrApiGateway sonarrApiGateway = Sonarr.api();
public void refreshSeries(Set<Integer> seriesToRefresh) {
for (var serieId : seriesToRefresh) {
Runnable refreshTask = () -> sonarrApiGateway.refreshSerie(serieId);
if (!ConfigLoader.isTestMode())
deferredRefresher.schedule(refreshTask, 5, TimeUnit.SECONDS);
}
}
}