-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Sentry::Cron::MonitorCheckIns
module for automatic monitoring o…
…f jobs Standard job frameworks such as `ActiveJob` and `Sidekiq` can now use this module to automatically capture check ins. ```rb class ExampleJob < ApplicationJob include Sentry::Cron::MonitorCheckIns sentry_monitor_check_ins def perform(*args) # do stuff end end ``` ```rb class SidekiqJob include Sidekiq::Job include Sentry::Cron::MonitorCheckIns sentry_monitor_check_ins def perform(*args) # do stuff end end ``` You can pass in optional attributes to `sentry_monitor_check_ins` as follows. ```rb sentry_monitor_check_ins slug: 'custom_slug' sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_interval(1, :minute) sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_crontab('5 * * * *') ```
- Loading branch information
1 parent
3d0ed07
commit 571e522
Showing
7 changed files
with
484 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module Sentry | ||
module Cron | ||
module MonitorCheckIns | ||
module Patch | ||
def perform(*args) | ||
slug = self.class.sentry_monitor_slug || self.class.name | ||
monitor_config = self.class.sentry_monitor_config | ||
|
||
check_in_id = Sentry.capture_check_in(slug, | ||
:in_progress, | ||
monitor_config: monitor_config) | ||
|
||
start = Sentry.utc_now.to_i | ||
ret = super | ||
duration = Sentry.utc_now.to_i - start | ||
|
||
Sentry.capture_check_in(slug, | ||
:ok, | ||
check_in_id: check_in_id, | ||
duration: duration, | ||
monitor_config: monitor_config) | ||
|
||
ret | ||
rescue Exception | ||
duration = Sentry.utc_now.to_i - start | ||
|
||
Sentry.capture_check_in(slug, | ||
:error, | ||
check_in_id: check_in_id, | ||
duration: duration, | ||
monitor_config: monitor_config) | ||
|
||
raise | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def sentry_monitor_check_ins(slug: nil, monitor_config: nil) | ||
@sentry_monitor_slug = slug | ||
@sentry_monitor_config = monitor_config | ||
|
||
prepend Patch | ||
end | ||
|
||
def sentry_monitor_slug | ||
@sentry_monitor_slug | ||
end | ||
|
||
def sentry_monitor_config | ||
@sentry_monitor_config | ||
end | ||
end | ||
|
||
extend ClassMethods | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.