-
Notifications
You must be signed in to change notification settings - Fork 510
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
Cronjob monitoring isn't very ergonomic if you're not using an automatic integration #2770
Comments
Thanks @Lexicality, this is good feedback! Since you've had to sort of work around the current API, do you have any suggestions how you'd like the API to look? |
@sentrivana The current context manager approach is great, however in the same way that you can configure transactions with |
To be clearer, I'd prefer my custom baseclass to look like this: class BaseCronJob(BaseCommand):
def run_cronjob(self):
raise NotImplementedError("You must override the `run_cronjob` method!")
name: Optional[str] = None
def __init__(self, *args, **kwargs) -> None:
name_override = os.environ.get("CRONJOB_NAME")
if name_override is not None:
self.name = name_override
super().__init__(*args, **kwargs)
def create_parser(self, prog_name: str, subcommand: str, **kwargs):
# Cheeky hack for figuring out the cronjob name from the command name
if self.name is None:
self.name = subcommand.replace("_", "-")
return super().create_parser(prog_name, subcommand, **kwargs)
def handle(self, *args, **options):
with sentry_sdk.monitor(
self.name,
crontab_schedule=os.getenv("CRONJOB_SCHEDULE"),
checkin_margin=os.getenv("CRONJOB_STARTUP_DEADLINE"),
):
self.stdout.write(f"Starting cronjob {self.name}", self.style.NOTICE)
try:
self.run_cronjob()
except Exception:
self.stdout.write(f"Cronjob {self.name} failed", self.style.ERROR)
raise
else:
self.stdout.write(f"Cronjob {self.name} succeeded", self.style.SUCCESS) |
Thanks @Lexicality, that makes sense to me -- adding this to our backlog. |
We'll be working on something like this as part of #2925 -- the API will be slightly different but it should make the |
Thank you! Is there a plan for |
@Lexicality No plans for creating transactions around crons, so that still needs to be done manually. |
Good to know, thanks for sorting the upsert |
Problem Statement
The
sentry.monitor()
context manager is incredibly basic and doesn't set up transactions, tags or allow you to configure cronjobs via upsertSolution Brainstorm
My current solution is this baseclass which works, but it's not great and I'm fairly wary about pulling unexported functions from inner modules.
The text was updated successfully, but these errors were encountered: