-
Notifications
You must be signed in to change notification settings - Fork 112
More tests, docs, and minor things #41
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
Changes from all commits
1b0fdc2
f3f6962
75d0e48
21b4f2d
8dad0fe
fc99e79
18e3e23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "sdk-core"] | ||
path = temporalio/bridge/sdk-core | ||
url = git@github.com:temporalio/sdk-core.git | ||
url = https://github.com/temporalio/sdk-core.git |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
"""Common code used in the Temporal SDK.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from datetime import timedelta | ||
from enum import IntEnum | ||
|
@@ -35,8 +37,26 @@ class RetryPolicy: | |
non_retryable_error_types: Optional[Iterable[str]] = None | ||
"""List of error types that are not retryable.""" | ||
|
||
@staticmethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like being explicit on class instantiation here (and I have chosen to use
cretz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def from_proto(proto: temporalio.api.common.v1.RetryPolicy) -> RetryPolicy: | ||
"""Create a retry policy from the proto object.""" | ||
return RetryPolicy( | ||
initial_interval=proto.initial_interval.ToTimedelta(), | ||
backoff_coefficient=proto.backoff_coefficient, | ||
maximum_interval=proto.maximum_interval.ToTimedelta() | ||
if proto.HasField("maximum_interval") | ||
else None, | ||
maximum_attempts=proto.maximum_attempts, | ||
non_retryable_error_types=proto.non_retryable_error_types | ||
if proto.non_retryable_error_types | ||
else None, | ||
) | ||
|
||
def apply_to_proto(self, proto: temporalio.api.common.v1.RetryPolicy) -> None: | ||
"""Apply the fields in this policy to the given proto object.""" | ||
# Do validation before converting | ||
self._validate() | ||
# Convert | ||
proto.initial_interval.FromTimedelta(self.initial_interval) | ||
proto.backoff_coefficient = self.backoff_coefficient | ||
proto.maximum_interval.FromTimedelta( | ||
|
@@ -46,6 +66,25 @@ def apply_to_proto(self, proto: temporalio.api.common.v1.RetryPolicy) -> None: | |
if self.non_retryable_error_types: | ||
proto.non_retryable_error_types.extend(self.non_retryable_error_types) | ||
|
||
def _validate(self) -> None: | ||
# Validation taken from Go SDK's test suite | ||
if self.maximum_attempts == 1: | ||
# Ignore other validation if disabling retries | ||
return | ||
if self.initial_interval.total_seconds() < 0: | ||
raise ValueError("Initial interval cannot be negative") | ||
if self.backoff_coefficient < 1: | ||
raise ValueError("Backoff coefficient cannot be less than 1") | ||
if self.maximum_interval: | ||
if self.maximum_interval.total_seconds() < 0: | ||
raise ValueError("Maximum interval cannot be negative") | ||
if self.maximum_interval < self.initial_interval: | ||
raise ValueError( | ||
"Maximum interval cannot be less than initial interval" | ||
) | ||
if self.maximum_attempts < 0: | ||
raise ValueError("Maximum attempts cannot be negative") | ||
|
||
|
||
class WorkflowIDReusePolicy(IntEnum): | ||
"""How already-in-use workflow IDs are handled on start. | ||
|
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.
Are you going to get rid of this soon?
Uh oh!
There was an error while loading. Please reload this page.
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.
There are two things in Go right now: Temporalite wrapper and "kitchen-sink" workflow/worker. I am waiting on TLS support and distributed Temporalite binaries for the former. For the latter, probably at the same time I get rid of the former, I will rewrite the workflow in Python and get rid of the Go worker.
I could move to docker compose I suppose, though Temporalite is very fast for our use case.