Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions sentry-ruby/lib/sentry/cron/monitor_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ class MonitorConfig
# @return [String, nil]
attr_accessor :timezone

def initialize(schedule, checkin_margin: nil, max_runtime: nil, timezone: nil)
# How many consecutive failed check-ins it takes to create an issue.
# @return [Integer, nil]
attr_accessor :failure_issue_threshold

# How many consecutive successful check-ins it takes to resolve an issue.
# @return [Integer, nil]
attr_accessor :recovery_threshold

def initialize(schedule, checkin_margin: nil, max_runtime: nil, timezone: nil, failure_issue_threshold: nil, recovery_threshold: nil)
@schedule = schedule
@checkin_margin = checkin_margin
@max_runtime = max_runtime
@timezone = timezone
@failure_issue_threshold = failure_issue_threshold
@recovery_threshold = recovery_threshold
end

def self.from_crontab(crontab, **options)
Expand All @@ -45,7 +55,9 @@ def to_h
schedule: schedule.to_h,
checkin_margin: checkin_margin,
max_runtime: max_runtime,
timezone: timezone
timezone: timezone,
failure_issue_threshold: failure_issue_threshold,
recovery_threshold: recovery_threshold
}.compact
end
end
Expand Down
18 changes: 18 additions & 0 deletions sentry-ruby/spec/sentry/cron/monitor_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@
end
end

describe 'tolerances' do
it 'accepts failure_issue_threshold and recovery_threshold' do
subject = described_class.from_crontab(
'5 * * * *',
failure_issue_threshold: 3,
recovery_threshold: 2
)

expect(subject.failure_issue_threshold).to eq(3)
expect(subject.recovery_threshold).to eq(2)
expect(subject.to_h).to eq({
schedule: { type: :crontab, value: '5 * * * *' },
failure_issue_threshold: 3,
recovery_threshold: 2
})
end
end

describe '#to_h' do
it 'returns hash with correct attributes for crontab' do
subject = described_class.from_crontab(
Expand Down