Skip to content
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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ The monitor's slug will be the actor's name. Like `my_task` in the example above
Certain triggers are not supported by Sentry as well as sub-minute intervals.
In these cases, no monitor will be created and no telemetry will be sent.

Pass a custom config via `sentry_monitor_config` or set it to `False`
Pass a custom config via `sentry_monitor_config` or set it to `None`
to disable Sentry monitoring for a single task:

```python
@cron("* * * * *", sentry_monitor_config=False)
@cron("* * * * *", sentry_monitor_config=None)
@task
Comment thread
codingjoe marked this conversation as resolved.
def my_task_without_sentry(): ...
```
Expand Down
11 changes: 7 additions & 4 deletions crontask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ def add_job(self, *args, **kwargs):


scheduler = LazyBlockingScheduler()
UNSET = object()


def cron(
schedule: str | BaseTrigger,
*,
sentry_monitor_config: dict[str, typing.Any] | bool | None = None,
sentry_monitor_config: dict[str, dict[str, str | int] | str] | None = UNSET,
) -> typing.Callable[[Task], Task]:
Comment thread
codingjoe marked this conversation as resolved.
"""
Run task on a scheduler with a cron schedule.
Expand All @@ -52,7 +53,7 @@ def cron_test():

Args:
schedule: A cron schedule string or an APScheduler trigger.
sentry_monitor_config: A Sentry monitor configuration dict or False to disable monitoring.
sentry_monitor_config: A Sentry monitor configuration dict or None to disable monitoring.

"""

Expand All @@ -73,11 +74,13 @@ def decorator(task: Task) -> Task:
else:
trigger = schedule

if sentry_monitor_config is not False:
if sentry_monitor_config is not None:
task = sentry.monitor_cron_task(
task,
trigger,
sentry_monitor_config=sentry_monitor_config,
sentry_monitor_config={}
if sentry_monitor_config is UNSET
else sentry_monitor_config,
Comment thread
codingjoe marked this conversation as resolved.
)

scheduler.add_job(
Expand Down
2 changes: 1 addition & 1 deletion crontask/contrib/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def trigger_to_monitor_config(
def monitor_cron_task(
task: Task,
trigger: BaseTrigger,
sentry_monitor_config: dict[str, dict[str, str | int] | str] | None = None,
sentry_monitor_config: dict[str, dict[str, str | int] | str],
) -> Task:
"""
Wrap the task function in a Sentry monitor for a suitable trigger.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_cron__sentry_monitor_config_false(monkeypatch):
mock_monitor = Mock(return_value=tasks.heartbeat)
monkeypatch.setattr("crontask.sentry.monitor_cron_task", mock_monitor)

cron("* * * * *", sentry_monitor_config=False)(tasks.heartbeat)
cron("* * * * *", sentry_monitor_config=None)(tasks.heartbeat)

mock_monitor.assert_not_called()
assert len(scheduler.get_jobs()) == 1
Expand Down Expand Up @@ -166,4 +166,4 @@ def test_cron__sentry_monitor_config_none(monkeypatch):

mock_monitor.assert_called_once()
call_args = mock_monitor.call_args
assert call_args.kwargs["sentry_monitor_config"] is None
assert call_args.kwargs["sentry_monitor_config"] == {}
Loading