-
Notifications
You must be signed in to change notification settings - Fork 104
Activity worker refactor #860
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the biggest fan of de-inlining single-use logic for running an activity from run_activity when it is only used in one place. If anything, I could understand exception handling being de-inlined if it was really too long for you. But not enough disagreement to prevent the change.
As explained in the intro, the logic inside the try...except was 170 lines long. That's always considered unacceptably long in Python codebases in my experience, and it's standard to de-inline in such situations even though it will be single use. Standards may differ in some compiled languages, but in dynamic languages like Python there's a strong emphasis on readability because of the risk of making mistakes that won't be discovered until run-time (and that risk was even greater in the pre-static-typing era in which Python coding style conventions became establised). |
Meh mostly only long because of the forced wrapping, it's not that many statements. Regardless, if this is too long for you, my suggestion is to extract out the |
33e32c4
to
1aa3165
Compare
As I've said, in Python codebases with good style conventions, one never places 170 lines nested inside a Standards may differ in some compiled languages, but in dynamic languages like Python there's a strong emphasis on readability because of the risk of making mistakes that won't be discovered until run-time (and that risk was even greater in the pre-static-typing era in which Python coding style conventions became establised). |
temporalio/worker/_activity.py
Outdated
@@ -201,6 +201,7 @@ async def drain_poll_queue(self) -> None: | |||
|
|||
# Only call this after run()/drain_poll_queue() have returned. This will not | |||
# raise an exception. | |||
# TODO(dan): check accuracy of this comment; I would say it *does* raise an exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cretz can you help resolve this TODO / question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's probably a mostly true statement because the _run_activity
is written to hopefully trap exceptions, but I think the intention was to set return_exceptions=True
instead of False
below, so that's probably what we should do here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, yes that's exactly what I was thinking. Updated TODO comment to that effect and leaving it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be totally ok changing the parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, yes let's investigate that. But this is a pure refactoring PR and I don't like mixing functional changes with refactoring.
1aa3165
to
365f567
Compare
990e89f
to
cbb26d7
Compare
This is pure refactoring for readability. I found it very helpful while creating a Nexus worker that is similar in some respects to the activity worker. All this PR does is move us to this pattern:
i.e. separating the execution logic from the error handling, since it's very hard to read a
try...except
with 170 lines in the middle.