Browse Source

Java CRONS wrapper support (#59604)

Docs for Java CRONS wrapper support including upsert (which hasn't been
released yet).

<!-- Describe your PR here. -->



<!--

  Sentry employees and contractors can delete or ignore the following.

-->

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.
Alexander Dinauer 1 year ago
parent
commit
729b0e7c91
1 changed files with 10 additions and 51 deletions
  1. 10 51
      static/app/views/monitors/components/quickStartEntries.tsx

+ 10 - 51
static/app/views/monitors/components/quickStartEntries.tsx

@@ -320,38 +320,12 @@ sentry.CaptureCheckIn(
 export function JavaCronQuickStart(props: QuickStartProps) {
   const {slug} = withDefaultProps(props);
 
-  const checkInSuccessCode = `import io.sentry.CheckIn;
-import io.sentry.CheckInStatus;
-import io.sentry.Sentry;
-import io.sentry.protocol.SentryId;
+  const checkInSuccessCode = `import io.sentry.util.CheckInUtils;
 
-// 🟡 Notify Sentry your job is running:
-SentryId checkInId = Sentry.captureCheckIn(
-    new CheckIn(
-        "${slug}",
-        CheckInStatus.IN_PROGRESS
-    )
-);
-
-// Execute your scheduled task here...
-
-// 🟢 Notify Sentry your job has completed successfully:
-Sentry.captureCheckIn(
-    new CheckIn(
-        checkInId,
-        "${slug}",
-        CheckInStatus.OK
-    )
-);`;
-
-  const checkInFailCode = `// 🔴 Notify Sentry your job has failed:
-Sentry.captureCheckIn(
-    new CheckIn(
-        checkInId,
-        "${slug}",
-        CheckInStatus.ERROR
-    )
-);`;
+String result = CheckInUtils.withCheckIn("${slug}", () -> {
+    // Execute your scheduled task here...
+    return "computed result";
+});`;
 
   return (
     <Fragment>
@@ -364,8 +338,6 @@ Sentry.captureCheckIn(
         )}
       </div>
       <CodeSnippet language="java">{checkInSuccessCode}</CodeSnippet>
-      <div>{t('To notify Sentry if your job execution fails')}</div>
-      <CodeSnippet language="java">{checkInFailCode}</CodeSnippet>
     </Fragment>
   );
 }
@@ -674,6 +646,7 @@ MonitorSchedule monitorSchedule = MonitorSchedule.crontab("*/10 * * * *");
 MonitorSchedule monitorSchedule = MonitorSchedule.interval(10, MonitorScheduleUnit.MINUTE);`;
 
   const upsertCode = `import io.sentry.MonitorConfig;
+import io.sentry.util.CheckInUtils;
 
 // Create a config object
 MonitorConfig monitorConfig = new MonitorConfig(monitorSchedule);
@@ -681,24 +654,10 @@ monitorConfig.setTimezone("Europe/Vienna"); // Optional timezone
 monitorConfig.setCheckinMargin(5L); // Optional check-in margin in minutes
 monitorConfig.setMaxRuntime(15L); // Optional max runtime in minutes
 
-// 🟡 Notify Sentry your job is running:
-CheckIn checkIn = new CheckIn(
-    "<monitor-slug>",
-    CheckInStatus.IN_PROGRESS
-);
-checkIn.setMonitorConfig(monitorConfig);
-SentryId checkInId = Sentry.captureCheckIn(checkIn);
-
-// Execute your scheduled task here...
-
-// 🟢 Notify Sentry your job has completed successfully:
-Sentry.captureCheckIn(
-    new CheckIn(
-        checkInId,
-        "<monitor-slug>",
-        CheckInStatus.OK
-    )
-);`;
+String result = CheckInUtils.withCheckIn("<monitor-slug>", monitorConfig, () -> {
+    // Execute your scheduled task here...
+    return "computed result";
+});`;
 
   return (
     <Fragment>