sentry-good_job 7.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6614ae4fcea329de36cf94c4714ecea1e2d04a52cc9d1b6ce858191d4b64d215
4
- data.tar.gz: b6b295bfb43f089ede9b08d877e7a15704a9304dc1effe8803c10f07356b26a4
3
+ metadata.gz: 28d0fe7d65c678d096c49038f0ee0fd55ffcd3f31e60c2d4f552cb7a707c142d
4
+ data.tar.gz: 1d024a3e18e3c8bbb6253b4e7d075e981b4a0fef24931971d851e1ec26e4f2cd
5
5
  SHA512:
6
- metadata.gz: 8bd54198cb499fd5015958fd443a8371b1d2e65c383622a34c4ac44d318c33f063a948fae1bc08673b275d7fb00767c23e2144e7e9aa32bed83c76497f25f801
7
- data.tar.gz: a903b8e7f34e2517a803477a5047cca172173670350ce4b4b67610c4bd1c6a1f904a68c58914b7e93582bfb0b2ba4dea13af8447d6436bf50fa21c9caabb3be3
6
+ metadata.gz: 58f97439f622814877b76f7b95082146dba7c9f4f8d9ed454c4dffafeb396749df2c0a3e55d44caa694c7a41e55e21b4793a389aa93f00b2ea09ffa6a3e6c2a8
7
+ data.tar.gz: 83eb21e53b1f62abdb7977bfedb6077a8a31f57c7ef98ffb56297bdf64c2333e9c567cd53f406aaddf8fc03e6f469c9bde9684e20c1f31991d7dd5bc5b3f0d2c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.0.1 (2026-09-09)
4
+
5
+ - Warn when Good Job cron is empty while leaving setup available for a later reload
6
+ - Attach cron monitors when Rails finishes booting and reattach them when job classes reload
7
+ - Skip callable cron schedules with a warning instead of failing initialization
8
+ - Read string or symbol keys on cron job config
9
+ - Warn when Good Job cron is off, or when CLI options prevent confirming it during Rails boot
10
+ - Document that monitors are created or updated on the first check-in
11
+
3
12
  ## 7.0.0 (2026-09-07)
4
13
 
5
14
  - BREAKING: Require sentry-ruby 7 (`>= 7.0`, `< 8.0`)
data/README.md CHANGED
@@ -100,6 +100,10 @@ config.good_job.cron = {
100
100
  }
101
101
  ```
102
102
 
103
+ Sentry creates or updates monitors on the first check-in. `enable_cron_monitors` registers check-ins on job classes. It is not a substitute for `config.good_job.enable_cron = true` or `good_job start --enable-cron`.
104
+
105
+ Callable Good Job cron schedules continue to run, but this integration skips Sentry monitor configuration for them because they do not provide a static crontab.
106
+
103
107
  You can also manually set up cron monitoring:
104
108
 
105
109
  ```ruby
@@ -62,23 +62,22 @@ module Sentry
62
62
  end
63
63
  end
64
64
 
65
- # Main integration class that handles all cron monitoring setup
66
- # This class follows Good Job's integration patterns and Sentry's extension guidelines
67
65
  class Integration
68
- # Track whether setup has already been performed to prevent duplicates
69
66
  @setup_completed = false
70
67
  @reload_hooked = false
71
68
 
72
- # Set up monitoring for all scheduled jobs from Good Job configuration
73
69
  def self.setup_monitoring_for_scheduled_jobs
74
70
  return unless ::Sentry.initialized?
75
71
  return unless ::Sentry.configuration.good_job.enable_cron_monitors
76
72
  attach_reload_hook_if_available
77
73
  return if @setup_completed
74
+ return unless rails_application?
78
75
 
79
- return unless defined?(::Rails) && ::Rails.respond_to?(:application) && ::Rails.application
80
76
  cron_config = ::Rails.application.config.good_job.cron
81
- return if cron_config.blank?
77
+ if cron_config.nil? || cron_config == {}
78
+ log_empty_cron_skip
79
+ return
80
+ end
82
81
 
83
82
  added_jobs = []
84
83
  cron_config.each do |cron_key, job_config|
@@ -93,72 +92,49 @@ module Sentry
93
92
  else
94
93
  Sentry.configuration.sdk_logger.info "Sentry cron monitoring setup for #{cron_config.keys.size} scheduled jobs"
95
94
  end
95
+ log_cron_scheduler_disabled_if_needed
96
96
  end
97
97
 
98
- # Reset setup state (primarily for testing)
99
98
  def self.reset_setup_state!
100
99
  @setup_completed = false
101
100
  end
102
101
 
103
- # Set up monitoring for a specific job
104
102
  def self.setup_monitoring_for_job(cron_key, job_config)
105
- job_class_name = job_config[:class]
106
- cron_expression = job_config[:cron]
107
-
103
+ job_class_name = job_config[:class] || job_config["class"]
104
+ cron_expression = job_config[:cron] || job_config["cron"]
108
105
  return unless job_class_name && cron_expression
109
106
 
110
- # Defer job class constantization to avoid boot-time issues
111
- # The job class will be constantized when the job is actually executed
112
- # This prevents issues during development boot and circular dependencies
113
-
114
- # Store the monitoring configuration for later use
115
- # We'll set up the monitoring when the job class is first loaded
116
- deferred_setup = lambda do
117
- job_class = begin
118
- job_class_name.constantize
119
- rescue NameError => e
120
- Sentry.configuration.sdk_logger.warn "Could not find job class '#{job_class_name}' for Sentry cron monitoring: #{e.message}"
121
- return
122
- end
123
-
124
- # Include Sentry::Cron::MonitorCheckIns module for cron monitoring
125
- # only patch if not explicitly included in job by user
126
- unless job_class.ancestors.include?(Sentry::Cron::MonitorCheckIns)
127
- job_class.include(Sentry::Cron::MonitorCheckIns)
128
- end
129
-
130
- # Parse cron expression and create monitor config
131
- cron_without_tz, timezone = Sentry::GoodJob::CronHelpers::Helpers.parse_cron_with_timezone(cron_expression)
132
- monitor_config = Sentry::GoodJob::CronHelpers::Helpers.monitor_config_from_cron(cron_without_tz, timezone: timezone)
133
-
134
- if monitor_config
135
- # Configure Sentry cron monitoring - use cron_key as slug for consistency
136
- monitor_slug = Sentry::GoodJob::CronHelpers::Helpers.monitor_slug(cron_key)
137
-
138
- job_class.sentry_monitor_check_ins(
139
- slug: monitor_slug,
140
- monitor_config: monitor_config
141
- )
142
-
143
- job_class_name
144
- else
145
- Sentry.configuration.sdk_logger.warn "Could not create monitor config for #{job_class_name} with cron '#{cron_expression}'"
146
- nil
147
- end
107
+ if cron_expression.respond_to?(:call)
108
+ Sentry.configuration.sdk_logger.warn(
109
+ "Could not create a Sentry monitor for #{job_class_name}: a callable cron schedule has no static crontab"
110
+ )
111
+ return
148
112
  end
149
113
 
150
- # Set up monitoring when the job class is first loaded
151
- # This defers constantization until the job is actually needed
152
- if defined?(::Rails) && ::Rails.respond_to?(:application) && ::Rails.application
153
- ::Rails.application.config.after_initialize do
154
- deferred_setup.call
155
- end
156
- else
157
- # Fallback for non-Rails environments
158
- deferred_setup.call
114
+ job_class = begin
115
+ job_class_name.constantize
116
+ rescue NameError => e
117
+ Sentry.configuration.sdk_logger.warn "Could not find job class '#{job_class_name}' for Sentry cron monitoring: #{e.message}"
118
+ return
159
119
  end
160
120
 
161
- # Return the job name for logging purposes
121
+ unless job_class.ancestors.include?(Sentry::Cron::MonitorCheckIns)
122
+ job_class.include(Sentry::Cron::MonitorCheckIns)
123
+ end
124
+
125
+ cron_without_tz, timezone = Sentry::GoodJob::CronHelpers::Helpers.parse_cron_with_timezone(cron_expression)
126
+ monitor_config = Sentry::GoodJob::CronHelpers::Helpers.monitor_config_from_cron(cron_without_tz, timezone: timezone)
127
+
128
+ unless monitor_config
129
+ Sentry.configuration.sdk_logger.warn "Could not create monitor config for #{job_class_name} with cron '#{cron_expression}'"
130
+ return
131
+ end
132
+
133
+ monitor_slug = Sentry::GoodJob::CronHelpers::Helpers.monitor_slug(cron_key)
134
+ job_class.sentry_monitor_check_ins(
135
+ slug: monitor_slug,
136
+ monitor_config: monitor_config
137
+ )
162
138
  job_class_name
163
139
  end
164
140
 
@@ -196,14 +172,66 @@ module Sentry
196
172
  return if @reload_hooked
197
173
  return unless defined?(::ActiveSupport::Reloader)
198
174
 
175
+ @reload_hooked = true
199
176
  ::ActiveSupport::Reloader.to_prepare do
200
- @setup_completed = false
177
+ Sentry::GoodJob::CronHelpers::Integration.reset_setup_state!
178
+ Sentry::GoodJob::CronHelpers::Integration.setup_monitoring_for_scheduled_jobs
201
179
  end
202
-
203
- @reload_hooked = true
204
180
  rescue NameError
181
+ @reload_hooked = false
205
182
  # ActiveSupport::Reloader not available in this environment
206
183
  end
184
+
185
+ def self.rails_application?
186
+ defined?(::Rails) && ::Rails.respond_to?(:application) && ::Rails.application
187
+ end
188
+
189
+ def self.log_empty_cron_skip
190
+ Sentry.configuration.sdk_logger.warn(
191
+ "Sentry cron monitors skipped: Good Job cron is empty (#{cron_process_context}). Setup will retry when a schedule is present."
192
+ )
193
+ end
194
+
195
+ def self.log_cron_scheduler_disabled_if_needed
196
+ case cron_process_state
197
+ when :enabled
198
+ return
199
+ when :cli_option_unknown
200
+ Sentry.configuration.sdk_logger.warn(
201
+ "Sentry cron monitor setup cannot confirm whether Good Job cron runs in this CLI process during Rails boot " \
202
+ "(#{cron_process_context}). Pass --enable-cron when starting Good Job unless Rails config enables cron."
203
+ )
204
+ return
205
+ end
206
+
207
+ Sentry.configuration.sdk_logger.warn(
208
+ "Sentry cron monitors will not appear until a job check-in runs. Good Job cron is off in this process (#{cron_process_context})."
209
+ )
210
+ end
211
+
212
+ def self.cron_process_state
213
+ return :enabled if good_job_config_value(:enable_cron)
214
+ return :cli_option_unknown if good_job_cli?
215
+
216
+ :disabled
217
+ end
218
+
219
+ def self.good_job_cli?
220
+ defined?(::GoodJob::CLI) && ::GoodJob::CLI.respond_to?(:within_exe?) && ::GoodJob::CLI.within_exe?
221
+ end
222
+
223
+ def self.cron_process_context
224
+ "process=#{$PROGRAM_NAME} enable_cron=#{good_job_config_value(:enable_cron).inspect} execution_mode=#{good_job_config_value(:execution_mode).inspect}"
225
+ end
226
+
227
+ def self.good_job_config_value(name)
228
+ return unless rails_application?
229
+
230
+ config = ::Rails.application.config.good_job
231
+ return unless config&.respond_to?(name)
232
+
233
+ config.public_send(name)
234
+ end
207
235
  end
208
236
  end
209
237
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sentry
4
4
  module GoodJob
5
- VERSION = "7.0.0"
5
+ VERSION = "7.0.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-good_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
@@ -253,7 +253,7 @@ metadata:
253
253
  source_code_uri: https://github.com/amkisko/sentry-good_job/tree/main
254
254
  changelog_uri: https://github.com/amkisko/sentry-good_job/blob/main/CHANGELOG.md
255
255
  bug_tracker_uri: https://github.com/amkisko/sentry-good_job/issues
256
- documentation_uri: http://www.rubydoc.info/gems/sentry-good_job/7.0.0
256
+ documentation_uri: http://www.rubydoc.info/gems/sentry-good_job/7.0.1
257
257
  rdoc_options: []
258
258
  require_paths:
259
259
  - lib