Skip to content

Commit 2efbb2c

Browse files
committed
Static method and custom warning category
1 parent 76ff2a9 commit 2efbb2c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

temporalio/converter.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,10 @@ class PayloadLimitsConfig:
12381238
"""The limit (in bytes) at which a payload size warning is logged."""
12391239

12401240

1241+
class PayloadSizeWarning(RuntimeWarning):
1242+
"""The size of encoded payloads is above the warning limit."""
1243+
1244+
12411245
@dataclass
12421246
class _PayloadErrorLimits:
12431247
memo_upload_error_limit: int
@@ -1430,7 +1434,7 @@ async def _encode_memo_existing(
14301434
memo.fields[k].CopyFrom(payload)
14311435
payloads.append(payload)
14321436
# Memos have their field payloads validated all together in one unit
1433-
self._validate_limits(
1437+
DataConverter._validate_limits(
14341438
payloads,
14351439
self._memo_upload_error_limit,
14361440
"[TMPRL1103] Attempted to upload memo with size that exceeded the error limit.",
@@ -1519,16 +1523,16 @@ def _validate_payload_limits(
15191523
self,
15201524
payloads: Sequence[temporalio.api.common.v1.Payload],
15211525
):
1522-
self._validate_limits(
1526+
DataConverter._validate_limits(
15231527
payloads,
15241528
self._payload_upload_error_limit,
15251529
"[TMPRL1103] Attempted to upload payloads with size that exceeded the error limit.",
15261530
self.payload_limits.payload_upload_warning_limit,
15271531
"[TMPRL1103] Attempted to upload payloads with size that exceeded the warning limit.",
15281532
)
15291533

1534+
@staticmethod
15301535
def _validate_limits(
1531-
self,
15321536
payloads: Sequence[temporalio.api.common.v1.Payload],
15331537
error_limit: int,
15341538
error_message: str,
@@ -1545,7 +1549,8 @@ def _validate_limits(
15451549
if warning_limit > 0 and total_size > warning_limit:
15461550
# TODO: Use a context aware logger to log extra information about workflow/activity/etc
15471551
warnings.warn(
1548-
f"{warning_message} Size: {total_size} bytes, Limit: {warning_limit} bytes"
1552+
f"{warning_message} Size: {total_size} bytes, Limit: {warning_limit} bytes",
1553+
PayloadSizeWarning,
15491554
)
15501555

15511556

0 commit comments

Comments
 (0)