1
0
Fork 0

make singleton the config loader and the sonarr API service

This commit is contained in:
Xavier Fontanet 2024-05-19 19:17:42 +02:00
parent db3f739682
commit cc110c6487
5 changed files with 33 additions and 8 deletions

View File

@ -6,5 +6,4 @@ services:
image: xeviff/sonarr_queue_fix:latest image: xeviff/sonarr_queue_fix:latest
volumes: volumes:
- ./config:/config - ./config:/config
- /volume1/data/torrents/tv:/data/torrents/tv - /volume1/data:/data
- /volume1/data/media/tv:/data/media/tv

View File

@ -5,11 +5,18 @@ import tv.mangrana.exception.IncorrectWorkingReferencesException;
public class ConfigFileLoader extends CommonConfigFileLoader<ConfigFileLoader.ProjectConfiguration> { public class ConfigFileLoader extends CommonConfigFileLoader<ConfigFileLoader.ProjectConfiguration> {
private static final String CONFIG_FILE = "SonarrFixerConfig.yml"; private static final String CONFIG_FILE = "SonarrFixerConfig.yml";
private static ConfigFileLoader service;
public ConfigFileLoader() throws IncorrectWorkingReferencesException { private ConfigFileLoader() throws IncorrectWorkingReferencesException {
super(ProjectConfiguration.class); super(ProjectConfiguration.class);
} }
public static ConfigFileLoader getLoader() throws IncorrectWorkingReferencesException {
if (service==null)
service = new ConfigFileLoader();
return service;
}
public enum ProjectConfiguration { public enum ProjectConfiguration {
UPLOADS_PATHS UPLOADS_PATHS
} }

View File

@ -0,0 +1,16 @@
package tv.mangrana.sonarr;
import tv.mangrana.config.ConfigFileLoader;
import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway;
public class Sonarr {
private static SonarrApiGateway service;
public static void initService(ConfigFileLoader configFileLoader) {
service = new SonarrApiGateway(configFileLoader);
}
public static SonarrApiGateway api() {
return service;
}
}

View File

@ -2,6 +2,7 @@ package tv.mangrana.worker;
import tv.mangrana.config.ConfigFileLoader; import tv.mangrana.config.ConfigFileLoader;
import tv.mangrana.exception.IncorrectWorkingReferencesException; import tv.mangrana.exception.IncorrectWorkingReferencesException;
import tv.mangrana.sonarr.Sonarr;
public class MainWorker { public class MainWorker {
@ -13,8 +14,9 @@ public class MainWorker {
} }
public MainWorker() throws IncorrectWorkingReferencesException { public MainWorker() throws IncorrectWorkingReferencesException {
ConfigFileLoader configFileLoader = new ConfigFileLoader(); var configLoader = ConfigFileLoader.getLoader();
queueFixer = new QueueFixer(configFileLoader); Sonarr.initService(configLoader);
queueFixer = new QueueFixer();
} }
private void work() { private void work() {

View File

@ -1,6 +1,6 @@
package tv.mangrana.worker; package tv.mangrana.worker;
import tv.mangrana.config.ConfigFileLoader; import tv.mangrana.sonarr.Sonarr;
import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway; import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway;
import tv.mangrana.sonarr.api.schema.queue.Record; import tv.mangrana.sonarr.api.schema.queue.Record;
import tv.mangrana.sonarr.api.schema.series.SonarrSerie; import tv.mangrana.sonarr.api.schema.series.SonarrSerie;
@ -16,8 +16,8 @@ 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.";
private final SonarrApiGateway sonarrApiGateway; private final SonarrApiGateway sonarrApiGateway;
QueueFixer(ConfigFileLoader configFileLoader) { QueueFixer() {
sonarrApiGateway = new SonarrApiGateway(configFileLoader); sonarrApiGateway = Sonarr.api();
} }
void fix() { void fix() {
@ -61,6 +61,7 @@ public class QueueFixer {
.fix(); .fix();
} catch (IOException e) { } catch (IOException e) {
System.out.printf("!! could not fix the import %s%n", record.getTitle()); System.out.printf("!! could not fix the import %s%n", record.getTitle());
e.printStackTrace();
} }
} }