make singleton the config loader and the sonarr API service
This commit is contained in:
parent
db3f739682
commit
cc110c6487
|
@ -6,5 +6,4 @@ services:
|
|||
image: xeviff/sonarr_queue_fix:latest
|
||||
volumes:
|
||||
- ./config:/config
|
||||
- /volume1/data/torrents/tv:/data/torrents/tv
|
||||
- /volume1/data/media/tv:/data/media/tv
|
||||
- /volume1/data:/data
|
|
@ -5,11 +5,18 @@ import tv.mangrana.exception.IncorrectWorkingReferencesException;
|
|||
public class ConfigFileLoader extends CommonConfigFileLoader<ConfigFileLoader.ProjectConfiguration> {
|
||||
|
||||
private static final String CONFIG_FILE = "SonarrFixerConfig.yml";
|
||||
private static ConfigFileLoader service;
|
||||
|
||||
public ConfigFileLoader() throws IncorrectWorkingReferencesException {
|
||||
private ConfigFileLoader() throws IncorrectWorkingReferencesException {
|
||||
super(ProjectConfiguration.class);
|
||||
}
|
||||
|
||||
public static ConfigFileLoader getLoader() throws IncorrectWorkingReferencesException {
|
||||
if (service==null)
|
||||
service = new ConfigFileLoader();
|
||||
return service;
|
||||
}
|
||||
|
||||
public enum ProjectConfiguration {
|
||||
UPLOADS_PATHS
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package tv.mangrana.worker;
|
|||
|
||||
import tv.mangrana.config.ConfigFileLoader;
|
||||
import tv.mangrana.exception.IncorrectWorkingReferencesException;
|
||||
import tv.mangrana.sonarr.Sonarr;
|
||||
|
||||
public class MainWorker {
|
||||
|
||||
|
@ -13,8 +14,9 @@ public class MainWorker {
|
|||
}
|
||||
|
||||
public MainWorker() throws IncorrectWorkingReferencesException {
|
||||
ConfigFileLoader configFileLoader = new ConfigFileLoader();
|
||||
queueFixer = new QueueFixer(configFileLoader);
|
||||
var configLoader = ConfigFileLoader.getLoader();
|
||||
Sonarr.initService(configLoader);
|
||||
queueFixer = new QueueFixer();
|
||||
}
|
||||
|
||||
private void work() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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.schema.queue.Record;
|
||||
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.";
|
||||
private final SonarrApiGateway sonarrApiGateway;
|
||||
|
||||
QueueFixer(ConfigFileLoader configFileLoader) {
|
||||
sonarrApiGateway = new SonarrApiGateway(configFileLoader);
|
||||
QueueFixer() {
|
||||
sonarrApiGateway = Sonarr.api();
|
||||
}
|
||||
|
||||
void fix() {
|
||||
|
@ -61,6 +61,7 @@ public class QueueFixer {
|
|||
.fix();
|
||||
} catch (IOException e) {
|
||||
System.out.printf("!! could not fix the import %s%n", record.getTitle());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue