Skip to content

Commit

Permalink
feat(ruby): Add cron upsert docs (#8319)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Oct 24, 2023
1 parent 6fe5406 commit f932340
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/platform-includes/crons/setup/ruby.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,50 @@ If your job execution fails, you can notify Sentry about the failure:
```ruby
Sentry.capture_check_in('<monitor-slug>', :error)
```

## Upserting Cron Monitors

You can create and update your Monitors programmatically with code
rather than [creating and configuring them in Sentry.io](https://sentry.io/crons/create/).

First create a config object from either a crontab or an interval.

```ruby
# Create a config from a crontab schedule (every 10 minutes)
monitor_config = Sentry::Cron::MonitorConfig.from_crontab(
'5 * * * *',
checkin_margin: 5, # Optional check-in margin in minutes
max_runtime: 15, # Optional max runtime in minutes
timezone: 'Europe/Vienna', # Optional timezone
)

# Create a config from an interval schedule (every 10 minutes)
monitor_config = Sentry::Cron::MonitorConfig.from_interval(
10,
:minute,
checkin_margin: 5, # Optional check-in margin in minutes
max_runtime: 15, # Optional max runtime in minutes
timezone: 'Europe/Vienna', # Optional timezone
)
```

Then, use that config object during your check-ins.

```ruby
# 🟡 Notify Sentry your job is running:
check_in_id = Sentry.capture_check_in(
'<monitor-slug>',
:in_progress,
monitor_config: monitor_config
)

# Execute your scheduled task here...

# 🟢 Notify Sentry your job has completed successfully:
Sentry.capture_check_in(
'<monitor-slug>',
:ok,
check_in_id: check_in_id,
monitor_config: monitor_config
)`
```

1 comment on commit f932340

@vercel
Copy link

@vercel vercel bot commented on f932340 Oct 24, 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 – ./

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

Please sign in to comment.