MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / counterIncrement

Function counterIncrement

apps/cloud/src/engine/execution-rate-limit.ts:464–493  ·  view source on GitHub ↗
(namespace: RateLimiterNamespace)

Source from the content-addressed store, hash-verified

462 */
463const counterIncrement =
464 (namespace: RateLimiterNamespace): RateLimitIncrement =>
465 (organizationId, windowId) =>
466 Effect.tryPromise({
467 try: () => {
468 const stub = namespace.get(
469 namespace.idFromName(organizationId),
470 ) as ExecutionRateLimiterStub;
471 return stub.increment(windowId);
472 },
473 catch: (cause) => {
474 // oxlint-disable-next-line executor/no-instanceof-error, executor/no-unknown-error-message -- boundary: the Durable Object RPC rejects with a plain platform Error whose message text is the only classification signal Cloudflare gives
475 const reason = cause instanceof Error ? cause.message : String(cause);
476 return new RateLimitCounterError({
477 organizationId,
478 code: counterErrorCode(reason),
479 reason,
480 cause,
481 });
482 },
483 }).pipe(
484 Effect.tapError((error) =>
485 Effect.annotateCurrentSpan({
486 "rate_limit.counter.error_tag": "RateLimitCounterError",
487 "rate_limit.counter.error_code": error.code,
488 }),
489 ),
490 Effect.withSpan("rate_limit.increment", {
491 attributes: { "rate_limit.window_id": windowId },
492 }),
493 );
494
495/**
496 * The per-org hourly cap: the `EXECUTION_RATE_LIMIT_PER_HOUR` env override

Callers 1

Calls 4

counterErrorCodeFunction · 0.85
incrementMethod · 0.80
getMethod · 0.65
idFromNameMethod · 0.45

Tested by

no test coverage detected