Skip to content

Commit

Permalink
better logging if omdb api fails internally
Browse files Browse the repository at this point in the history
  • Loading branch information
mynttt committed Jan 8, 2020
1 parent 50fdfb2 commit 06e25f4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.3
1.2.4
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'eclipse'
}

version = '1.2.3'
version = '1.2.4'
sourceCompatibility = '11'

new File(projectDir, "VERSION").text = version;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/updatetool/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class Main {
}
}

public static String version() {
return VERSION;
}

public enum Implementations {
IMDB_DOCKER("imdb-docker",
"Watchdog mode implementation, will update ratings every n hours",
Expand Down Expand Up @@ -102,7 +106,6 @@ public static void main(String[] args) throws Exception {
System.exit(-1);
}

Logger.info("Running version: " + VERSION);
var constructor = impls.get(0).entry.getConstructor(new Class[0]);
constructor.newInstance().invoke(args);
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/updatetool/imdb/ImdbDockerImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.tinylog.Logger;
import org.tinylog.configuration.Configuration;
import updatetool.Main;
import updatetool.api.Implementation;
import updatetool.api.JobReport.StatusCode;
Expand All @@ -36,6 +38,22 @@ public void invoke(String[] args) throws Exception {
Objects.requireNonNull(apikeyOmdb, "Environment variable OMDB_API_KEY is not set");
Objects.requireNonNull(data, "Environment variable PLEX_DATA_DIR is not set");

var levels = List.of("trace", "debug", "info", "error", "warn");
String logging = System.getenv("LOG_LEVEL");

if(logging != null) {
logging = logging.toLowerCase();
if(levels.contains(logging.toLowerCase())) {
Configuration.set("writer.level", logging);
Configuration.set("writer2.level", logging);
System.out.println("Logging level changed to: " + logging);
} else {
Logger.warn("Ignoring custom log level. Logging level {} not in allowed levels: {}", logging, levels);
}
}

Logger.info("Running version: {}", Main.version());

plexdata = Path.of(data);

if(!Files.exists(plexdata) && !Files.isDirectory(plexdata)) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/updatetool/imdb/ImdbOmdbWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ public Void call() throws Exception {
if(response.statusCode() == 401)
throw new RatelimitException();

if(response.statusCode() != 200 || !result.Response)
if(response.statusCode() != 200 || !result.Response) {
Logger.error("OMDB_API_FAIL := TITLE -> {} | IMDB_ID -> {} | GUID -> {} | RESPONSE_CODE -> {} | RESPONSE_BODY -> {}", item.title, item.imdbId, item.guid, response.statusCode(), response.body());
throw new ApiCallFailedException("API call failed with code " + response.statusCode() + " after + " + RETRY_BEFORE_FAILURE + " attempt(s): " + response.body());
}

int c = counter.incrementAndGet();
if(c % 100 == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.3
1.2.4

0 comments on commit 06e25f4

Please sign in to comment.