From f9323401c800bae090f411b5373ba577b1694f4d Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Tue, 24 Oct 2023 14:36:32 +0200 Subject: [PATCH] feat(ruby): Add cron upsert docs (#8319) --- src/platform-includes/crons/setup/ruby.mdx | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/platform-includes/crons/setup/ruby.mdx b/src/platform-includes/crons/setup/ruby.mdx index 215674b751638..43d7533b3a613 100644 --- a/src/platform-includes/crons/setup/ruby.mdx +++ b/src/platform-includes/crons/setup/ruby.mdx @@ -71,3 +71,50 @@ If your job execution fails, you can notify Sentry about the failure: ```ruby Sentry.capture_check_in('', :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( + '', + :in_progress, + monitor_config: monitor_config +) + +# Execute your scheduled task here... + +# 🟢 Notify Sentry your job has completed successfully: +Sentry.capture_check_in( + '', + :ok, + check_in_id: check_in_id, + monitor_config: monitor_config +)` +```