Skip to content

ref(crons): Simplify example, add async note #9574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 3, 2024
Merged
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
4 changes: 4 additions & 0 deletions docs/platforms/python/crons/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ Still having trouble? Reach out to [crons-feedback@sentry.io](mailto:crons-feedb
### Why Are My Monitors Showing Up as Failed?

The SDK might be experiencing network issues. Learn more about <PlatformLink to="/troubleshooting/#network-issues">troubleshooting network issues</PlatformLink>.

### Can I Monitor Async Tasks as Well?

Yes, just make sure you're using SDK version `1.44.1` or higher since that's when support for monitoring async functions was added.
27 changes: 20 additions & 7 deletions platform-includes/crons/setup/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,32 @@ If you're using **Celery Beat** to run your periodic tasks, have a look at our [

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.

Use the `monitor` decorator to wrap your tasks:

```python
import sentry_sdk
from sentry_sdk.crons import monitor

# Add the @monitor decorator to your task
@monitor(monitor_slug='<monitor-slug>')
def tell_the_world(msg):
# Scheduled task here...
print(msg)
def tell_the_world():
print('My scheduled task...')
```

Alternatively, `monitor` can be used as a context manager:

```python
import sentry_sdk
from sentry_sdk.crons import monitor

# monitor can also be used as a context manager
def tell_the_world_contextmanager(msg):
def tell_the_world():
with monitor(monitor_slug='<monitor-slug>'):
# Scheduled task here...
print(msg)
print('My scheduled task...')
```

<Note>

Since version `1.44.1` of the SDK you can use `monitor` to annotate asynchronous
functions as well.

</Note>