-
Notifications
You must be signed in to change notification settings - Fork 104
Patch support and random/UUID helpers #35
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.
Nice, not a lot of work. Good to be seeing payoff from using Core.
path are done and will never be queried again. Therefore the old code path | ||
is removed as well. |
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 necessary for this PR, but probably makes sense to link to docs page explaining the patch lifecycle
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.
Unfortunately that doesn't exist for Python yet. https://docs.temporal.io/typescript/patching will be perfect in Python form if/when it exists. I have opened #37 to track this.
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.
It should probably be part of the app dev guide
def _apply_update_random_seed( | ||
self, job: temporalio.bridge.proto.workflow_activation.UpdateRandomSeed | ||
) -> None: | ||
self._random = random.Random(job.randomness_seed) |
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'd probably reseed the current _random
reference in case users keep a reference to it
(https://docs.python.org/3/library/random.html#random.seed)
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.
Ah, of course, duh. Fixing.
Returns: | ||
A deterministically-seeded v4 UUID. | ||
""" | ||
return uuid.UUID(bytes=random().getrandbits(16 * 8).to_bytes(16, "big"), version=4) |
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.
This is so much better than what I had to do in TS to get random and uuid.
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.
Saw that. This could be even better if I was able to use Random.randbytes()
as present in 3.9+.
I hesitated adding these APIs at all because I was hoping a sandbox could provide the random
and uuid
modules, but we might as well have these available now (and technically we still may offer a no-sandbox approach in the future).
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.
If we do have sandbox in the future we'll probably reuse these random and uuid implementations
What was changed
patched()
anddeprecate_patch()
workflow functions impl'd similar to TS onesrandom()
workflow function that returns a seeded random for use by usersuuid4()
workflow function that uses the random callChecklist