@@ -103,8 +103,6 @@ def test_cron_job_generated_id(sentry_init, capture_envelopes):
103103 (300 , {"type" : "interval" , "value" : 5 , "unit" : "minute" }),
104104 (7200 , {"type" : "interval" , "value" : 2 , "unit" : "hour" }),
105105 (86400 , {"type" : "interval" , "value" : 1 , "unit" : "day" }),
106- (30 , None ),
107- (90 , None ),
108106 ],
109107)
110108def test_interval_job (sentry_init , capture_envelopes , interval , schedule ):
@@ -121,20 +119,75 @@ def test_interval_job(sentry_init, capture_envelopes, interval, schedule):
121119 assert [c ["status" ] for c in check_ins ] == ["in_progress" , "ok" ]
122120 assert {c ["monitor_slug" ] for c in check_ins } == {"poll" }
123121 for check_in in check_ins :
124- assert check_in .get ("monitor_config" ) == (
125- None if schedule is None else {"schedule" : schedule }
122+ assert check_in ["monitor_config" ] == {"schedule" : schedule }
123+
124+
125+ @pytest .mark .parametrize ("interval" , [30 , 90 ])
126+ def test_unsupported_interval_not_monitored (sentry_init , capture_envelopes , interval ):
127+ sentry_init (integrations = [RqIntegration (monitor_cron_jobs = True )])
128+ envelopes = capture_envelopes ()
129+
130+ _run (
131+ lambda s : s .schedule (
132+ datetime .now (timezone .utc ), ok_job , interval = interval , id = "poll"
126133 )
134+ )
135+
136+ assert _check_ins (envelopes ) == []
137+
138+
139+ def test_unsupported_cron_string_not_monitored (sentry_init , capture_envelopes ):
140+ sentry_init (integrations = [RqIntegration (monitor_cron_jobs = True )])
141+ envelopes = capture_envelopes ()
142+
143+ _run (lambda s : s .cron ("0 0 1 * 1" , func = ok_job , id = "first-or-monday" ))
144+
145+ assert _check_ins (envelopes ) == []
146+
147+
148+ def test_local_time_cron_not_monitored (monkeypatch , sentry_init , capture_envelopes ):
149+ _set_local_timezone (monkeypatch , "America/New_York" )
150+ sentry_init (integrations = [RqIntegration (monitor_cron_jobs = True )])
151+ envelopes = capture_envelopes ()
152+
153+ _run (lambda s : s .cron ("0 * * * *" , func = ok_job , id = "hourly" ))
154+
155+ assert _check_ins (envelopes ) == []
127156
128157
129- def test_repeat_job_without_config (sentry_init , capture_envelopes ):
158+ def test_repeat_job_not_monitored (sentry_init , capture_envelopes ):
130159 sentry_init (integrations = [RqIntegration (monitor_cron_jobs = True )])
131160 envelopes = capture_envelopes ()
132161
133162 _run (lambda s : s .cron ("0 * * * *" , func = ok_job , id = "limited" , repeat = 3 ))
134163
135- check_ins = _check_ins (envelopes )
136- assert [c ["status" ] for c in check_ins ] == ["in_progress" , "ok" ]
137- assert all ("monitor_config" not in c for c in check_ins )
164+ assert _check_ins (envelopes ) == []
165+
166+
167+ def test_perform_job_raises (monkeypatch , sentry_init , capture_envelopes ):
168+ sentry_init (integrations = [RqIntegration (monitor_cron_jobs = True )])
169+ envelopes = capture_envelopes ()
170+
171+ def handle_execution_ended (* args , ** kwargs ):
172+ raise ConnectionError ("redis down" )
173+
174+ connection = FakeStrictRedis ()
175+ queue = rq .Queue (connection = connection )
176+ scheduler = rq_scheduler .Scheduler (queue = queue , connection = connection )
177+ job = scheduler .cron ("0 * * * *" , func = ok_job , id = "hourly" )
178+ scheduler .enqueue_job (job )
179+ worker = rq .SimpleWorker ([queue ], connection = connection )
180+ # Raises from rq's own exception handler too.
181+ monkeypatch .setattr (worker , "handle_execution_ended" , handle_execution_ended )
182+
183+ with pytest .raises (ConnectionError ):
184+ worker .perform_job (job , queue )
185+
186+ in_progress , error = _check_ins (envelopes )
187+ assert in_progress ["status" ] == "in_progress"
188+ assert error ["status" ] == "error"
189+ assert error ["check_in_id" ] == in_progress ["check_in_id" ]
190+ assert error ["monitor_config" ] == in_progress ["monitor_config" ]
138191
139192
140193def test_one_off_jobs_not_monitored (sentry_init , capture_envelopes ):
0 commit comments