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

Add Job.__repr__() #8703

Merged
merged 1 commit into from
May 8, 2024
Merged

Add Job.__repr__() #8703

merged 1 commit into from
May 8, 2024

Conversation

seanh
Copy link
Contributor

@seanh seanh commented May 8, 2024

This is gonna be useful for monitoring and debugging when jobs appear in log messages and tracebacks, Sentry issues, etc.

This is gonna be useful for monitoring and debugging when jobs appear in
log messages and tracebacks, Sentry issues, etc.
@seanh seanh requested a review from marcospri May 8, 2024 11:05

assert (
repr(job)
== "Job(id=42, name='job_name', enqueued_at=datetime.datetime(2024, 5, 8, 11, 51, 23), scheduled_at=datetime.datetime(2024, 6, 1, 0, 0), expires_at=datetime.datetime(2025, 1, 1, 0, 0), priority=3, tag='job_tag', kwargs={'foo': 'FOO', 'bar': 'BAR'})"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repr looks like valid Python code that could be used to instantiate a matching job object, as recommended by the Python docs: https://docs.python.org/3.11/reference/datamodel.html#object.__repr__ Including all the attrs makes it quite long but most useful for debugging

attrs = {
attrname: repr(getattr(self, attrname))
for attrname in [
"id",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitelisting 👍

@seanh seanh merged commit 8c58d05 into main May 8, 2024
9 checks passed
@seanh seanh deleted the add-Job.__repr__ branch May 8, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants