Skip to content

Commit

Permalink
Add javascript documentation for Crons upsert (#8723)
Browse files Browse the repository at this point in the history
* add node.js documentation for crons upsert

* [getsentry/action-github-commit] Auto commit

* add crons upsert to remaining javascript platforms

* Apply copy suggestions from crons upsert code review

Co-authored-by: vivianyentran <[email protected]>

* [getsentry/action-github-commit] Auto commit

* separate crons upsert monitor config in upsert example

* [getsentry/action-github-commit] Auto commit

* apply additional formatting editing to crons check-ins

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Co-authored-by: vivianyentran <[email protected]>
  • Loading branch information
3 people authored Dec 14, 2023
1 parent 5ff4c2a commit 40df9e1
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 0 deletions.
150 changes: 150 additions & 0 deletions src/includes/javascript-crons-upsert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
You can create and update your Monitors programmatically with code rather than [creating and configuring them in Sentry.io](https://sentry.io/crons/create/).

To create/update a monitor, use `Sentry.withMonitor()` and pass in your monitor configuration as a third parameter:

```javascript
const monitorConfig = {
schedule: {
type: "crontab",
value: "* * * * *",
},
checkinMargin: 2, // In minutes. Optional.
maxRuntime: 10, // In minutes. Optional.
timezone: "America/Los_Angeles", // Optional.
};

Sentry.withMonitor(
"<monitor-slug>",
() => {
// Execute your scheduled task here...
},
monitorConfig
);
```

```typescript
import { MonitorConfig } from "@sentry/types";

const monitorConfig: MonitorConfig = {
schedule: {
type: "crontab",
value: "* * * * *",
},
checkinMargin: 2, // In minutes. Optional.
maxRuntime: 10, // In minutes. Optional.
timezone: "America/Los_Angeles", // Optional.
};

Sentry.withMonitor(
"<monitor-slug>",
() => {
// Execute your scheduled task here...
},
monitorConfig
);
```

To configure the monitor's check-ins, use `Sentry.captureCheckIn()` and pass in your monitor configuration as a second parameter:

```javascript
const monitorConfig = {
schedule: {
type: "crontab",
value: "* * * * *",
},
checkinMargin: 2, // In minutes. Optional.
maxRuntime: 10, // In minutes. Optional.
timezone: "America/Los_Angeles", // Optional.
};

// 🟡 Notify Sentry your job is running:
const checkInId = Sentry.captureCheckIn(
{
monitorSlug: "<monitor-slug>",
status: "in_progress",
},
monitorConfig
);

// Execute your scheduled task here...

// 🟢 Notify Sentry your job has completed successfully:
Sentry.captureCheckIn(
{
// Make sure this variable is named `checkInId`
checkInId,
monitorSlug: "<monitor-slug>",
status: "ok",
},
monitorConfig
);
```

```typescript
import { MonitorConfig } from "@sentry/types";

const monitorConfig: MonitorConfig = {
schedule: {
type: "crontab",
value: "* * * * *",
},
checkinMargin: 2, // In minutes. Optional.
maxRuntime: 10, // In minutes. Optional.
timezone: "America/Los_Angeles", // Optional.
};

// 🟡 Notify Sentry your job is running:
const checkInId = Sentry.captureCheckIn(
{
monitorSlug: "<monitor-slug>",
status: "in_progress",
},
monitorConfig
);

// Execute your scheduled task here...

// 🟢 Notify Sentry your job has completed successfully:
Sentry.captureCheckIn(
{
// Make sure this variable is named `checkInId`
checkInId,
monitorSlug: "<monitor-slug>",
status: "ok",
},
monitorConfig
);
```

### Monitor Configuration Properties

The following are available monitor configuration properties:

`schedule`:

: The job's schedule:

The schedule representation for your monitor, either `crontab` or `interval`. The structure will vary depending on the type:

```json
{"type": "crontab", "value": "0 * * * *"}
{"type": "interval", "value": "2", "unit": "hour"}
```

`checkinMargin`:

: The amount of time (in minutes) Sentry should wait for your check-in before it's considered missed ("grace period"). Optional.

<Note>

We recommend that your check-in margin be less than or equal to your interval.

</Note>

`maxRuntime`:

: The amount of time (in minutes) your job is allowed to run before it's considered failed. Optional.

`timezone`:

: The `tz` where your job is running. This is usually your server's timezone, (such as `America/Los_Angeles`). See [list of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Optional.
4 changes: 4 additions & 0 deletions src/platform-includes/crons/setup/javascript.astro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ Cron monitoring is only supported in Astro server-side
## Check-Ins

<Include name="javascript-crons-checkins.mdx" />

## Upserting Cron Monitors

<Include name="javascript-crons-upsert.mdx" />
4 changes: 4 additions & 0 deletions src/platform-includes/crons/setup/javascript.bun.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
## Check-Ins

<Include name="javascript-crons-checkins.mdx" />

## Upserting Cron Monitors

<Include name="javascript-crons-upsert.mdx" />
4 changes: 4 additions & 0 deletions src/platform-includes/crons/setup/javascript.nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ Set the `automaticVercelMonitors` option to `true` in your Sentry settings in `n
## Check-Ins

<Include name="javascript-crons-checkins.mdx" />

## Upserting Cron Monitors

<Include name="javascript-crons-upsert.mdx" />
4 changes: 4 additions & 0 deletions src/platform-includes/crons/setup/javascript.remix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ Cron monitoring is only supported in Remix server-side
## Check-Ins

<Include name="javascript-crons-checkins.mdx" />

## Upserting Cron Monitors

<Include name="javascript-crons-upsert.mdx" />
4 changes: 4 additions & 0 deletions src/platform-includes/crons/setup/javascript.sveltekit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ Cron monitoring is only supported in SvelteKit server-side
## Check-Ins

<Include name="javascript-crons-checkins.mdx" />

## Upserting Cron Monitors

<Include name="javascript-crons-upsert.mdx" />
4 changes: 4 additions & 0 deletions src/platform-includes/crons/setup/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
## Check-Ins

<Include name="javascript-crons-checkins.mdx" />

## Upserting Cron Monitors

<Include name="javascript-crons-upsert.mdx" />

1 comment on commit 40df9e1

@vercel
Copy link

@vercel vercel bot commented on 40df9e1 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sentry-docs – ./

sentry-docs-git-master.sentry.dev
sentry-docs.sentry.dev
docs.sentry.io

Please sign in to comment.