pub struct RateLimitsClient { /* private fields */ }Expand description
Creates and raises the tenant’s rate limits.
Get one from Client::rate_limits. A static
RateLimit on a task spends an allowance that has to
exist first, and this is what creates it — the official Python SDK’s
rate_limits().put(..) over the same v0 WorkflowService/PutRateLimit
call (sdks/python/hatchet_sdk/features/rate_limits.py:31-65). A
dynamic rate limit carries its own allowance in
limit_expr and needs nothing here.
Order matters. A task that declares a static
RateLimit whose key
was never put fails registration with a bare
Internal error and no further detail — observed against both
supported engine versions. Put the key before registering the worker
that uses it:
use hatchet_client::{RateLimit, RateLimitDuration, TaskBuilder};
// 1. Create (or raise) the allowance first.
client
.rate_limits()
.put("github-api", 5_000, RateLimitDuration::Hour)
.await?;
// 2. Only now register a task that spends it.
let call_api = TaskBuilder::<(), ()>::new("call-api")
.rate_limit(RateLimit::new("github-api", 1))
.handler(|_ctx, _input| async { Ok(()) });
client.worker("api-worker").register(&call_api).build().await?;Keys are tenant-global and not namespaced: the client’s namespace
configured with ClientBuilder::namespace
is not applied here, matching the official Python SDK. Two environments
sharing a tenant share these keys.
Implementations§
Source§impl RateLimitsClient
impl RateLimitsClient
Sourcepub async fn put(
&self,
key: impl AsRef<str>,
limit: u32,
duration: RateLimitDuration,
) -> Result<()>
pub async fn put( &self, key: impl AsRef<str>, limit: u32, duration: RateLimitDuration, ) -> Result<()>
Sets the allowance for key to limit per duration, creating it
if it is new and replacing whatever it was before.
key is not namespaced; see the RateLimitsClient docs.
§Errors
Error::InvalidArgument when key
is empty or all whitespace — checked before any call is made, rather
than left to the engine’s own InvalidArgument. Otherwise
Error::Grpc when the call fails.
Trait Implementations§
Source§impl Clone for RateLimitsClient
impl Clone for RateLimitsClient
Auto Trait Implementations§
impl !RefUnwindSafe for RateLimitsClient
impl !UnwindSafe for RateLimitsClient
impl Forget for RateLimitsClient
impl Freeze for RateLimitsClient
impl Move for RateLimitsClient
impl Send for RateLimitsClient
impl Sync for RateLimitsClient
impl Unpin for RateLimitsClient
impl UnsafeUnpin for RateLimitsClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request