dbos-inc / dbos-transact-py

Ultra-Lightweight Durable Execution in Python
https://docs.dbos.dev
MIT License
244 stars 7 forks source link

Rate Limiting Queue #119

Closed kraftp closed 1 month ago

kraftp commented 1 month ago

You can now pass in a "limiter" to a queue, for example:

queue = Queue("test_queue", limiter={"max": max, "duration": duration})

The queue will start at most max tasks in any given duration seconds. This is useful when submitting jobs to rate-limited APIs. For example, if your API only accepts 100 requests per minute, set a max of 100 and a duration of 60.

chuck-dbos commented 1 month ago

First comment - can we make it milliseconds?

kraftp commented 1 month ago

First comment - can we make it milliseconds?

I switched the type to float--that way it's consistent with other Python duration APIs like sleep or DBOS.sleep that expect a time in seconds but allow subsecond precision.