Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #92 from libgraviton/feature/some-updates
Browse files Browse the repository at this point in the history
Feature/some updates
  • Loading branch information
narcoticfresh authored Mar 11, 2024
2 parents 7afed12 + fe6780c commit c386d1f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.libgraviton</groupId>
<artifactId>worker-base</artifactId>
<packaging>jar</packaging>
<version>4.1.0-SNAPSHOT</version>
<version>4.1.0</version>
<name>Graviton Worker Base Library</name>
<url>https://github.com/libgraviton/graviton-worker-base-java</url>
<inceptionYear>2015</inceptionYear>
Expand Down Expand Up @@ -41,8 +41,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dependency.locations.enabled>false</dependency.locations.enabled>
<dependency.details.enabled>false</dependency.details.enabled>
<jackson-jr.version>2.16.1</jackson-jr.version>
<log4j.version>2.22.1</log4j.version>
<jackson-jr.version>2.16.2</jackson-jr.version>
<log4j.version>2.23.1</log4j.version>
</properties>

<repositories>
Expand Down Expand Up @@ -124,7 +124,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.11</version>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -213,7 +213,7 @@
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j2</artifactId>
<version>7.2.0</version>
<version>7.6.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down Expand Up @@ -253,14 +253,14 @@
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.165</version>
<version>4.8.168</version>
</dependency>

<!-- metrics -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.12.2</version>
<version>1.12.3</version>
</dependency>
<dependency>
<groupId>io.github.mweirauch</groupId>
Expand Down Expand Up @@ -298,7 +298,7 @@
<dependency>
<groupId>com.github.libgraviton</groupId>
<artifactId>graviton-worker-test-base</artifactId>
<version>4.0.0</version>
<version>4.1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -310,7 +310,7 @@
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.3.1</version>
<version>3.4.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -438,13 +438,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.9.0</version>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
47 changes: 39 additions & 8 deletions src/main/java/com/github/libgraviton/workerbase/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
import com.github.libgraviton.workerbase.exception.WorkerException;
import com.github.libgraviton.workerbase.helper.DependencyInjection;
import com.github.libgraviton.workerbase.helper.WorkerProperties;
import io.sentry.Sentry;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

public class Application {
public static void main(String[] args) throws IOException, WorkerException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
WorkerProperties.load();
DependencyInjection.init();

// try to persist them
WorkerProperties.persist();
public static void main(String[] args) throws IOException, WorkerException {
Properties workerProperties = initPropertiesAndSentry();

Set<Class<?>> workerClasses = DependencyInjection.getWorkerClasses();

Expand Down Expand Up @@ -61,9 +57,44 @@ public static void main(String[] args) throws IOException, WorkerException, Clas

final WorkerLauncher workerLauncher = new WorkerLauncher(
worker,
DependencyInjection.getInstance(Properties.class)
workerProperties,
getApplicationName(workerProperties)
);

workerLauncher.run();
}

private static Properties initPropertiesAndSentry() throws IOException {
WorkerProperties.load();
DependencyInjection.init();

// try to persist them
WorkerProperties.persist();

Properties workerProperties = DependencyInjection.getInstance(Properties.class);

Sentry.init(options -> {
String dsn = System.getenv("SENTRY_DSN");

if (null != dsn && !dsn.isBlank()) {
options.setDsn(dsn);
options.setEnabled(true);
}

options.setRelease(
String.format(
"%s@%s",
getApplicationName(workerProperties),
workerProperties.getProperty("application.version")
)
);
});

return workerProperties;
}

private static String getApplicationName(Properties properties)
{
return properties.getProperty("graviton.workerName") != null ? properties.getProperty("graviton.workerName") : properties.getProperty("application.name");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.github.libgraviton.workerbase.exception.WorkerException;
import com.github.libgraviton.workerbase.util.PrometheusServer;
import com.sun.net.httpserver.HttpServer;
import io.activej.inject.annotation.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -34,19 +33,14 @@ public final class WorkerLauncher {
private final PrometheusServer prometheusServer;
private final QueueWorkerRunner queueWorkerRunner;

@Inject
public WorkerLauncher(
WorkerInterface worker,
Properties properties
Properties properties,
String applicationName
) {

this.worker = worker;

String applicationName = properties.getProperty("application.name");
if (properties.getProperty("graviton.workerName") != null) {
applicationName = properties.getProperty("graviton.workerName");
}

LOG.info(
"Starting '{} {}' (class '{}', worker-base '{}'). Runtime '{}' version '{}', TZ '{}'",
applicationName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
Expand All @@ -30,7 +31,7 @@ public void setup() throws Exception {

RequestExecutor executor = mock(RequestExecutor.class);
when(executor.execute(any(Request.class))).thenReturn(response);
URL url = new URL("http://aRandomUrl");
URL url = new URI("http://aRandomUrl").toURL();
builder = new Request.Builder().setUrl(url);
}

Expand Down Expand Up @@ -117,7 +118,7 @@ public void testMultipartPut() throws Exception {
Assertions.assertEquals(HttpMethod.PUT, request.getMethod());
List<Part> parts = request.getParts();
Assertions.assertEquals(1, parts.size());
Assertions.assertEquals(part, parts.get(0));
Assertions.assertEquals(part, parts.getFirst());
}

@Test
Expand Down

0 comments on commit c386d1f

Please sign in to comment.