-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
755 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public final class io/sentry/quartz/BuildConfig { | ||
public static final field SENTRY_QUARTZ_SDK_NAME Ljava/lang/String; | ||
public static final field VERSION_NAME Ljava/lang/String; | ||
} | ||
|
||
public final class io/sentry/quartz/SentryJobListener : org/quartz/JobListener { | ||
public static final field SENTRY_CHECK_IN_ID_KEY Ljava/lang/String; | ||
public static final field SENTRY_SLUG_KEY Ljava/lang/String; | ||
public fun <init> ()V | ||
public fun <init> (Lio/sentry/IHub;)V | ||
public fun getName ()Ljava/lang/String; | ||
public fun jobExecutionVetoed (Lorg/quartz/JobExecutionContext;)V | ||
public fun jobToBeExecuted (Lorg/quartz/JobExecutionContext;)V | ||
public fun jobWasExecuted (Lorg/quartz/JobExecutionContext;Lorg/quartz/JobExecutionException;)V | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import net.ltgt.gradle.errorprone.errorprone | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
`java-library` | ||
kotlin("jvm") | ||
jacoco | ||
id(Config.QualityPlugins.errorProne) | ||
id(Config.QualityPlugins.gradleVersions) | ||
id(Config.BuildPlugins.buildConfig) version Config.BuildPlugins.buildConfigVersion | ||
} | ||
|
||
configure<JavaPluginExtension> { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
tasks.withType<KotlinCompile>().configureEach { | ||
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
kotlinOptions.languageVersion = Config.kotlinCompatibleLanguageVersion | ||
} | ||
|
||
dependencies { | ||
api(projects.sentry) | ||
compileOnly(Config.Libs.quartz) | ||
|
||
compileOnly(Config.CompileOnly.nopen) | ||
errorprone(Config.CompileOnly.nopenChecker) | ||
errorprone(Config.CompileOnly.errorprone) | ||
errorprone(Config.CompileOnly.errorProneNullAway) | ||
compileOnly(Config.CompileOnly.jetbrainsAnnotations) | ||
|
||
// tests | ||
testImplementation(projects.sentry) | ||
testImplementation(projects.sentryTestSupport) | ||
testImplementation(kotlin(Config.kotlinStdLib)) | ||
testImplementation(Config.TestLibs.kotlinTestJunit) | ||
testImplementation(Config.TestLibs.mockitoKotlin) | ||
testImplementation(Config.TestLibs.mockitoInline) | ||
} | ||
|
||
configure<SourceSetContainer> { | ||
test { | ||
java.srcDir("src/test/java") | ||
} | ||
} | ||
|
||
jacoco { | ||
toolVersion = Config.QualityPlugins.Jacoco.version | ||
} | ||
|
||
tasks.jacocoTestReport { | ||
reports { | ||
xml.required.set(true) | ||
html.required.set(false) | ||
} | ||
} | ||
|
||
tasks { | ||
jacocoTestCoverageVerification { | ||
violationRules { | ||
rule { limit { minimum = Config.QualityPlugins.Jacoco.minimumCoverage } } | ||
} | ||
} | ||
check { | ||
dependsOn(jacocoTestCoverageVerification) | ||
dependsOn(jacocoTestReport) | ||
} | ||
} | ||
|
||
tasks.withType<JavaCompile>().configureEach { | ||
options.errorprone { | ||
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) | ||
option("NullAway:AnnotatedPackages", "io.sentry") | ||
} | ||
} | ||
|
||
buildConfig { | ||
useJavaOutput() | ||
packageName("io.sentry.quartz") | ||
buildConfigField("String", "SENTRY_QUARTZ_SDK_NAME", "\"${Config.Sentry.SENTRY_QUARTZ_SDK_NAME}\"") | ||
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"") | ||
} |
102 changes: 102 additions & 0 deletions
102
sentry-quartz/src/main/java/io/sentry/quartz/SentryJobListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.sentry.quartz; | ||
|
||
import io.sentry.BuildConfig; | ||
import io.sentry.CheckIn; | ||
import io.sentry.CheckInStatus; | ||
import io.sentry.HubAdapter; | ||
import io.sentry.IHub; | ||
import io.sentry.SentryIntegrationPackageStorage; | ||
import io.sentry.SentryLevel; | ||
import io.sentry.protocol.SentryId; | ||
import io.sentry.util.Objects; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.quartz.JobDataMap; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
import org.quartz.JobListener; | ||
|
||
@ApiStatus.Experimental | ||
public final class SentryJobListener implements JobListener { | ||
|
||
public static final String SENTRY_CHECK_IN_ID_KEY = "sentry-checkin-id"; | ||
public static final String SENTRY_SLUG_KEY = "sentry-slug"; | ||
|
||
private final @NotNull IHub hub; | ||
|
||
public SentryJobListener() { | ||
this(HubAdapter.getInstance()); | ||
} | ||
|
||
public SentryJobListener(final @NotNull IHub hub) { | ||
this.hub = Objects.requireNonNull(hub, "hub is required"); | ||
SentryIntegrationPackageStorage.getInstance().addIntegration("Quartz"); | ||
SentryIntegrationPackageStorage.getInstance() | ||
.addPackage("maven:io.sentry:sentry-quartz", BuildConfig.VERSION_NAME); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "sentry-job-listener"; | ||
} | ||
|
||
@Override | ||
public void jobToBeExecuted(final @NotNull JobExecutionContext context) { | ||
try { | ||
final @Nullable String maybeSlug = getSlug(context); | ||
if (maybeSlug == null) { | ||
return; | ||
} | ||
final @NotNull String slug = maybeSlug; | ||
final @NotNull CheckIn checkIn = new CheckIn(slug, CheckInStatus.IN_PROGRESS); | ||
final @NotNull SentryId checkInId = hub.captureCheckIn(checkIn); | ||
context.put(SENTRY_CHECK_IN_ID_KEY, checkInId); | ||
context.put(SENTRY_SLUG_KEY, slug); | ||
} catch (Throwable t) { | ||
hub.getOptions() | ||
.getLogger() | ||
.log(SentryLevel.ERROR, "Unable to capture check-in in jobToBeExecuted.", t); | ||
} | ||
} | ||
|
||
private @Nullable String getSlug(final @NotNull JobExecutionContext context) { | ||
final @Nullable JobDataMap jobDataMap = context.getMergedJobDataMap(); | ||
if (jobDataMap != null) { | ||
final @Nullable Object o = jobDataMap.get(SENTRY_SLUG_KEY); | ||
if (o != null) { | ||
return o.toString(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void jobExecutionVetoed(JobExecutionContext context) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { | ||
try { | ||
final @Nullable Object checkInIdObjectFromContext = context.get(SENTRY_CHECK_IN_ID_KEY); | ||
final @Nullable Object slugObjectFromContext = context.get(SENTRY_SLUG_KEY); | ||
final @NotNull SentryId checkInId = | ||
checkInIdObjectFromContext == null | ||
? new SentryId() | ||
: (SentryId) checkInIdObjectFromContext; | ||
final @Nullable String slug = | ||
slugObjectFromContext == null ? null : (String) slugObjectFromContext; | ||
if (slug != null) { | ||
final boolean isFailed = jobException != null; | ||
final @NotNull CheckInStatus status = isFailed ? CheckInStatus.ERROR : CheckInStatus.OK; | ||
hub.captureCheckIn(new CheckIn(checkInId, slug, status)); | ||
} | ||
} catch (Throwable t) { | ||
hub.getOptions() | ||
.getLogger() | ||
.log(SentryLevel.ERROR, "Unable to capture check-in in jobWasExecuted.", t); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ng-boot-jakarta/src/main/java/io/sentry/samples/spring/boot/jakarta/quartz/SampleJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.sentry.samples.spring.boot.jakarta.quartz; | ||
|
||
import org.quartz.Job; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SampleJob implements Job { | ||
|
||
public void execute(JobExecutionContext context) throws JobExecutionException { | ||
System.out.println("running job"); | ||
try { | ||
Thread.sleep(15000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/quartz.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.