Skip to content

Commit 3ea9e79

Browse files
authored
Pick up config.cron.default_timezone from Rails config (#2213)
* Pick up config.cron.default_timezone from Rails config * Update changelog
1 parent c9a79bf commit 3ea9e79

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
end
3636
```
3737

38+
- Pick up config.cron.default_timezone from Rails config ([#2213](https://github.com/getsentry/sentry-ruby/pull/2213))
39+
3840
## 5.15.2
3941

4042
### Bug Fixes

sentry-rails/lib/sentry/rails/railtie.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Railtie < ::Rails::Railtie
4040

4141
configure_project_root
4242
configure_trusted_proxies
43+
configure_cron_timezone
4344
extend_controller_methods if defined?(ActionController)
4445
patch_background_worker if defined?(ActiveRecord)
4546
override_streaming_reporter if defined?(ActionView)
@@ -70,6 +71,11 @@ def configure_trusted_proxies
7071
Sentry.configuration.trusted_proxies += Array(::Rails.application.config.action_dispatch.trusted_proxies)
7172
end
7273

74+
def configure_cron_timezone
75+
tz_info = ::ActiveSupport::TimeZone.find_tzinfo(::Rails.application.config.time_zone)
76+
Sentry.configuration.cron.default_timezone = tz_info.name
77+
end
78+
7379
def extend_controller_methods
7480
require "sentry/rails/controller_methods"
7581
require "sentry/rails/controller_transaction"

sentry-rails/spec/sentry/rails_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
expect(app.middleware.find_index(Sentry::Rails::RescuedExceptionInterceptor)).to eq(index_of_debug_exceptions + 1)
2727
end
2828

29+
it "propagates timezone to cron config" do
30+
# cron.default_timezone is set to nil by default
31+
expect(Sentry.configuration.cron.default_timezone).to eq("Etc/UTC")
32+
end
33+
2934
it "inserts a callback to disable background_worker for the runner mode" do
3035
Sentry.configuration.background_worker_threads = 10
3136

0 commit comments

Comments
 (0)