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
|
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
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.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() {
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue