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
10 changes: 9 additions & 1 deletion sentry-ruby/lib/sentry/cron/monitor_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ def self.from_crontab(crontab, **options)
end

def self.from_interval(num, unit, **options)
return nil unless MonitorSchedule::Interval::VALID_UNITS.include?(unit)
unless MonitorSchedule::Interval::VALID_UNITS.include?(unit)
if Sentry.initialized?
Sentry.sdk_logger.debug(LOGGER_PROGNAME) do
"Invalid interval unit #{unit.inspect} for monitor config, must be one of #{MonitorSchedule::Interval::VALID_UNITS.inspect}"
end
end

return nil
end

new(MonitorSchedule::Interval.new(num, unit), **options)
end
Expand Down
15 changes: 15 additions & 0 deletions sentry-ruby/spec/sentry/cron/monitor_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
expect(described_class.from_interval(5, :bla)).to eq(nil)
end

it 'logs a debug message without valid unit' do
string_io = StringIO.new
Sentry.configuration.sdk_logger = Logger.new(string_io)

described_class.from_interval(5, :bla)

expect(string_io.string).to include("Invalid interval unit :bla for monitor config")
end

it 'returns nil without valid unit when SDK is not initialized' do
allow(Sentry).to receive(:initialized?).and_return(false)

expect(described_class.from_interval(5, :bla)).to eq(nil)
end

it 'has correct attributes' do
subject = described_class.from_interval(
5,
Expand Down