Skip to content

Commit 24fdeaa

Browse files
wedamijaclaudesentrivana
authored
docs(crons): Add RQ setup for Python (#20058)
## DESCRIBE YOUR PR Adds an RQ section to the Python Crons setup page: turning on `monitor_cron_jobs` for rq-scheduler jobs, how the slug is picked, and which jobs are monitored. SDK PR: getsentry/sentry-python#8053 Stacked on #20057. Merge after the SDK release that includes it. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. Select exactly one option. For deadlines, replace `YYYY-MM-DD` with the due date. You can update this information later by editing the PR description. - [ ] Urgent deadline (GA date, etc.): YYYY-MM-DD - [ ] Other deadline: YYYY-MM-DD - [x] No deadline: Not urgent, can wait up to 1 week+ --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
1 parent 3a864da commit 24fdeaa

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎platform-includes/crons/setup/python.mdx‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,39 @@ def send_report():
7575

7676
The monitor slug is the task's name, which defaults to the function name. Sentry creates the monitor from the task's `crontab()` schedule in UTC. Periodic tasks aren't monitored when they use a custom schedule function, when their crontab sets both `day` and `day_of_week`, or when the Huey instance is created with `utc=False`.
7777

78+
### RQ
79+
80+
<Alert>
81+
82+
Crons monitoring for RQ ships in version `2.73.0` of `sentry-sdk`.
83+
84+
</Alert>
85+
86+
If you're using [RQ](/platforms/python/integrations/rq/) with [rq-scheduler](https://github.com/rq/rq-scheduler), set `monitor_cron_jobs=True` in your workers to capture check-ins for recurring jobs:
87+
88+
```python
89+
import sentry_sdk
90+
from sentry_sdk.integrations.rq import RqIntegration
91+
92+
sentry_sdk.init(
93+
dsn="___PUBLIC_DSN___",
94+
integrations=[
95+
RqIntegration(
96+
monitor_cron_jobs=True,
97+
# optional: regular expressions for jobs to skip
98+
exclude_cron_jobs=["cleanup"],
99+
),
100+
],
101+
)
102+
```
103+
104+
```python
105+
scheduler.cron("0 9 * * *", func=send_report, id="send-report")
106+
scheduler.schedule(datetime.now(timezone.utc), sync_accounts, interval=600, id="sync-accounts")
107+
```
108+
109+
The monitor slug is the job's `id`. Without an `id`, rq-scheduler generates a new one each time the job is scheduled, so the SDK uses the function's import path instead. Sentry creates the monitor from `cron()` jobs and from `schedule()` jobs whose `interval` is a whole number of minutes. rq-scheduler runs cron strings in the system's local time, so `cron()` jobs are only monitored when the worker's time zone is UTC. Jobs whose schedule can't be expressed in the Crons schedule format (for example, a job that runs every 10 seconds), jobs with `repeat`, and one-off jobs from `enqueue_at` and `enqueue_in` aren't monitored.
110+
78111
## Job Monitoring
79112

80113
Use the Python SDK to monitor and notify you if your periodic task is missed (or doesn't start when expected), if it fails due to a problem in the runtime (such as an error), or if it fails by exceeding its maximum runtime.

0 commit comments

Comments
 (0)