Files
hatchet/examples/python/rate_limit/dynamic.py
Gabe Ruttner 8e80faf2d6 Fe overhaul docs (#1640)
* api changes

* doc changes

* move docs

* generated

* generate

* pkg

* backmerge main

* revert to main

* revert main

* race?

* remove go tests
2025-04-30 14:10:09 -07:00

38 lines
815 B
Python

from pydantic import BaseModel
from hatchet_sdk import Context, Hatchet
from hatchet_sdk.rate_limit import RateLimit
hatchet = Hatchet(debug=True)
class DynamicRateLimitInput(BaseModel):
group: str
units: int
limit: int
dynamic_rate_limit_workflow = hatchet.workflow(
name="DynamicRateLimitWorkflow", input_validator=DynamicRateLimitInput
)
@dynamic_rate_limit_workflow.task(
rate_limits=[
RateLimit(
dynamic_key='"LIMIT:"+input.group',
units="input.units",
limit="input.limit",
)
]
)
def step1(input: DynamicRateLimitInput, ctx: Context) -> None:
print("executed step1")
def main() -> None:
worker = hatchet.worker(
"rate-limit-worker", slots=10, workflows=[dynamic_rate_limit_workflow]
)
worker.start()