Files
hatchet/python-sdk/examples/rate_limit/worker.py
Gabe Ruttner 91b0dda46e feat(py): global rate limits (#328)
* chore: regen protos

* feat: admin put rate limit

* fix: client type

* feat: rate limit example

* feat: workflow config

* feat: step config

* release: py 0.21.0

* fix: RateLimitDuration in init

---------

Co-authored-by: gabriel ruttner <gabe@hatchet.run>
2024-04-02 13:01:22 -04:00

24 lines
664 B
Python

from hatchet_sdk import Hatchet, Context
from dotenv import load_dotenv
from hatchet_sdk.rate_limit import RateLimit, RateLimitDuration
load_dotenv()
hatchet = Hatchet(debug=True)
@hatchet.workflow(on_events=["rate_limit:create"])
class RateLimitWorkflow:
def __init__(self):
self.my_value = "test"
@hatchet.step(rate_limits = [RateLimit(key='test-limit', units=1)])
def step1(self, context: Context):
print("executed step1")
pass
hatchet.client.admin.put_rate_limit('test-limit', 2, RateLimitDuration.MINUTE)
worker = hatchet.worker('test-worker', max_runs=4)
worker.register_workflow(RateLimitWorkflow())
worker.start()