Skip to content

Commit a3640c1

Browse files
juliusgeowsehl
authored andcommitted
Add wait and retry parameters to TenacityConfig (#3651)
1 parent 9c173b3 commit a3640c1

5 files changed

Lines changed: 24 additions & 15 deletions

File tree

sdks/python/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to Hatchet's Python SDK will be documented in this changelog
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.33.0] - 2026-04-16
9+
10+
### Changed
11+
12+
- Adds `wait` and `before_sleep` parameters to `TenacityConfig` to allow custom retry strategies and retry callbacks.
13+
814
## [1.32.3] - 2026-04-16
915

1016
### Changed

sdks/python/hatchet_sdk/clients/dispatcher/dispatcher.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
from hatchet_sdk.clients.dispatcher.action_listener import ActionListener
1111
from hatchet_sdk.clients.rest.tenacity_utils import (
12-
tenacity_alert_retry,
1312
tenacity_retry,
1413
tenacity_should_retry,
1514
)
16-
from hatchet_sdk.config import ClientConfig, TenacityConfig
15+
from hatchet_sdk.config import ClientConfig, TenacityConfig, tenacity_before_sleep
1716
from hatchet_sdk.connection import new_conn
1817
from hatchet_sdk.contracts.dispatcher_pb2 import (
1918
SDKS,
@@ -105,7 +104,7 @@ async def get_action_listener(
105104
reraise=True,
106105
wait=tenacity.wait_exponential_jitter(initial=0.5, max=5),
107106
stop=tenacity.stop_after_attempt(3),
108-
before_sleep=tenacity_alert_retry,
107+
before_sleep=tenacity_before_sleep,
109108
retry=tenacity.retry_if_exception(tenacity_should_retry),
110109
)
111110
async def get_version(self) -> str | None:

sdks/python/hatchet_sdk/clients/rest/tenacity_utils.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
ServiceException,
1313
TooManyRequestsException,
1414
)
15-
from hatchet_sdk.logger import logger
1615

1716
if TYPE_CHECKING:
1817
from hatchet_sdk.config import TenacityConfig
@@ -30,21 +29,13 @@ def should_retry(ex: BaseException) -> bool:
3029

3130
return tenacity.retry(
3231
reraise=True,
33-
wait=tenacity.wait_exponential_jitter(),
32+
wait=config.wait(),
3433
stop=tenacity.stop_after_attempt(config.max_attempts),
35-
before_sleep=tenacity_alert_retry,
34+
before_sleep=config.before_sleep,
3635
retry=tenacity.retry_if_exception(should_retry),
3736
)(func)
3837

3938

40-
def tenacity_alert_retry(retry_state: tenacity.RetryCallState) -> None:
41-
"""Called between tenacity retries."""
42-
logger.debug(
43-
f"retrying {retry_state.fn}: attempt "
44-
f"{retry_state.attempt_number} ended with: {retry_state.outcome}",
45-
)
46-
47-
4839
def tenacity_should_retry(
4940
ex: BaseException, config: TenacityConfig | None = None
5041
) -> bool:

sdks/python/hatchet_sdk/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import json
2+
from collections.abc import Callable
23
from datetime import timedelta
34
from enum import Enum
45
from logging import Logger, getLogger
56
from typing import overload
67

8+
import tenacity
79
from pydantic import Field, field_validator, model_validator
810
from pydantic_settings import BaseSettings, SettingsConfigDict
911

12+
from hatchet_sdk.logger import logger
1013
from hatchet_sdk.token import get_addresses_from_jwt, get_tenant_id_from_jwt
1114
from hatchet_sdk.utils.opentelemetry import OTelAttribute
1215

@@ -96,6 +99,14 @@ class HTTPMethod(str, Enum):
9699
OPTIONS = "OPTIONS"
97100

98101

102+
def tenacity_before_sleep(retry_state: tenacity.RetryCallState) -> None:
103+
"""Called between tenacity retries."""
104+
logger.debug(
105+
f"retrying {retry_state.fn}: attempt "
106+
f"{retry_state.attempt_number} ended with: {retry_state.outcome}",
107+
)
108+
109+
99110
class TenacityConfig(BaseSettings):
100111
model_config = create_settings_config(
101112
env_prefix="HATCHET_CLIENT_TENACITY_",
@@ -115,6 +126,8 @@ class TenacityConfig(BaseSettings):
115126
default_factory=lambda: [HTTPMethod.GET, HTTPMethod.DELETE],
116127
description="HTTP methods to retry on transport errors when retry_transport_errors is enabled; excludes POST/PUT/PATCH by default due to idempotency concerns.",
117128
)
129+
wait: type[tenacity.wait.wait_base] = tenacity.wait_exponential_jitter
130+
before_sleep: Callable[[tenacity.RetryCallState], None] = tenacity_before_sleep
118131

119132

120133
DEFAULT_HOST_PORT = "localhost:7070"

sdks/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "hatchet-sdk"
3-
version = "1.32.3"
3+
version = "1.33.0"
44
description = "This is the official Python SDK for Hatchet, a distributed, fault-tolerant task queue. The SDK allows you to easily integrate Hatchet's task scheduling and workflow orchestration capabilities into your Python applications."
55
readme = "README.md"
66
license = { text = "MIT" }

0 commit comments

Comments
 (0)