|
31 | 31 | from temporalio.api.common.v1 import Payload |
32 | 32 | from temporalio.client import ( |
33 | 33 | Client, |
| 34 | + WorkflowExecutionDescription, |
34 | 35 | WorkflowExecutionStatus, |
35 | 36 | WorkflowHandle, |
36 | 37 | WorkflowUpdateFailedError, |
|
42 | 43 |
|
43 | 44 | from ._topic_handle import TopicHandle |
44 | 45 | from ._types import ( |
| 46 | + STREAM_DRAINING_ERROR_TYPE, |
| 47 | + TRUNCATED_OFFSET_ERROR_TYPE, |
45 | 48 | PollInput, |
46 | 49 | PollResult, |
47 | 50 | PublishEntry, |
@@ -509,9 +512,11 @@ async def subscribe( |
509 | 512 | ``Payload`` — useful for heterogeneous topics where |
510 | 513 | the caller dispatches on ``Payload.metadata`` or wants |
511 | 514 | to forward the bytes without decoding. |
512 | | - poll_cooldown: Minimum interval between polls to avoid |
513 | | - overwhelming the workflow when items arrive faster |
514 | | - than the poll round-trip. Defaults to 100ms. |
| 515 | + poll_cooldown: Minimum interval between polls when caught |
| 516 | + up (backlogs always drain at full speed). Defaults to |
| 517 | + 100ms. Avoid ``timedelta(0)``: an idle subscriber |
| 518 | + busy-loops, and each poll grows workflow history toward |
| 519 | + its limit. Use 0 only in tests. |
515 | 520 |
|
516 | 521 | Yields: |
517 | 522 | :class:`WorkflowStreamItem` for each matching item. |
@@ -549,14 +554,14 @@ async def subscribe( |
549 | 554 | return |
550 | 555 | except WorkflowUpdateFailedError as e: |
551 | 556 | cause_type = getattr(e.cause, "type", None) |
552 | | - if cause_type == "TruncatedOffset": |
| 557 | + if cause_type == TRUNCATED_OFFSET_ERROR_TYPE: |
553 | 558 | # Subscriber fell behind truncation. Retry from |
554 | 559 | # offset 0 which the stream treats as "from the |
555 | 560 | # beginning of whatever exists" (i.e., from |
556 | 561 | # base_offset). |
557 | 562 | offset = 0 |
558 | 563 | continue |
559 | | - if cause_type == "StreamDraining": |
| 564 | + if cause_type == STREAM_DRAINING_ERROR_TYPE: |
560 | 565 | # Workflow is detaching for continue-as-new. Back off and |
561 | 566 | # retry; the poll lands on the successor run once the |
562 | 567 | # rollover completes. |
@@ -606,7 +611,7 @@ async def subscribe( |
606 | 611 | if not result.more_ready and cooldown_secs > 0: |
607 | 612 | await asyncio.sleep(cooldown_secs) |
608 | 613 |
|
609 | | - async def _describe_polled_run(self): |
| 614 | + async def _describe_polled_run(self) -> WorkflowExecutionDescription: |
610 | 615 | """Describe the specific run the most recent poll was admitted to. |
611 | 616 |
|
612 | 617 | Describing that run (rather than the latest) is what lets a |
|
0 commit comments