Skip to content
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

Attach sentry monitor to actor, not scheduler #7

Merged
merged 1 commit into from
Apr 30, 2023
Merged
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
11 changes: 5 additions & 6 deletions dramatiq_crontab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def cron_test():
The monitors timezone should be set to Europe/Berlin.
"""

def decorator(func):
def decorator(actor):
*_, day_of_week = schedule.split(" ")

if day_of_week.lower() not in (
Expand All @@ -60,20 +60,19 @@ def decorator(func):
"Please use a literal day of week (Mon, Tue, Wed, Thu, Fri, Sat, Sun) or *"
)

fn = getattr(func, "send")
if monitor is not None:
fn = monitor(func.actor_name)(fn)
actor.fn = monitor(actor.actor_name)(actor.fn)

scheduler.add_job(
fn,
actor.send,
CronTrigger.from_crontab(
schedule,
timezone=timezone.get_default_timezone(),
),
name=func.actor_name,
name=actor.actor_name,
)
# We don't add the Sentry monitor on the actor itself, because we only want to
# monitor the cron job, not the actor itself, or it's direct invocations.
return func
return actor

return decorator