Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 402f377

Browse files
committed
fix: sticky strategies
1 parent 8b376c3 commit 402f377

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

hatchet_sdk/v2/workflows.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
from enum import Enum
3-
from typing import Any, Callable, Generic, ParamSpec, Type, TypeVar, Union
3+
from typing import Any, Callable, Generic, ParamSpec, Type, TypeVar, Union, cast
44

55
from pydantic import BaseModel, ConfigDict
66

@@ -63,7 +63,7 @@ class WorkflowConfig(BaseModel):
6363
version: str = ""
6464
timeout: str = "60m"
6565
schedule_timeout: str = "5m"
66-
sticky: Union[StickyStrategy, None] = None
66+
sticky: StickyStrategy | None = None
6767
default_priority: int = 1
6868
concurrency: ConcurrencyExpression | None = None
6969
input_validator: Type[BaseModel] = EmptyModel
@@ -208,12 +208,17 @@ def validate_priority(self, default_priority: int | None) -> int | None:
208208

209209
return validated_priority
210210

211-
def validate_sticky(
212-
self, sticky: Union[StickyStrategy, None]
213-
) -> StickyStrategyProto | None:
214-
if sticky:
215-
return StickyStrategyProto(sticky)
216-
return None
211+
def validate_sticky(self, sticky: StickyStrategy | None) -> int | None:
212+
if not sticky:
213+
return None
214+
215+
names = [item.name for item in StickyStrategyProto.DESCRIPTOR.values]
216+
217+
for name in names:
218+
if name == sticky.name:
219+
return StickyStrategyProto.Value(sticky.name)
220+
221+
raise ValueError(f"Sticky strategy must be one of {names}. Got: {sticky}")
217222

218223
def get_create_opts(self, namespace: str) -> CreateWorkflowVersionOpts:
219224
service_name = self.get_service_name(namespace)
@@ -249,7 +254,7 @@ def get_create_opts(self, namespace: str) -> CreateWorkflowVersionOpts:
249254
event_triggers=event_triggers,
250255
cron_triggers=self.config.on_crons,
251256
schedule_timeout=self.config.schedule_timeout,
252-
sticky=self.validate_sticky(self.config.sticky),
257+
sticky=cast(str, self.validate_sticky(self.config.sticky)),
253258
jobs=[
254259
CreateWorkflowJobOpts(
255260
name=name,

0 commit comments

Comments
 (0)