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

Function resolveExemption

apps/cloud/src/engine/execution-rate-limit.ts:281–312  ·  view source on GitHub ↗
(organizationId: string)

Source from the content-addressed store, hash-verified

279 * known-paid org into a block mid-workload.
280 */
281 const resolveExemption = (organizationId: string): Effect.Effect<boolean> =>
282 Effect.suspend(() => {
283 if (!isExempt) return Effect.succeed(false);
284 const nowMs = now();
285 const cached = exemptionCache.get(organizationId);
286 if (cached && cached.expiresAtMs > nowMs) return Effect.succeed(cached.exempt);
287 return isExempt(organizationId).pipe(
288 Effect.timeoutOrElse({
289 duration: `${EXEMPTION_CHECK_TIMEOUT_MS} millis`,
290 orElse: () =>
291 Effect.fail(new ExemptionCheckTimeoutError({ timeoutMs: EXEMPTION_CHECK_TIMEOUT_MS })),
292 }),
293 Effect.map((exempt) => {
294 writeExemptionCache(organizationId, exempt, nowMs);
295 return exempt;
296 }),
297 Effect.catch((error: unknown) =>
298 Effect.gen(function* () {
299 yield* Effect.sync(() => {
300 console.warn(
301 `[rate-limit] exemption lookup failed for ${organizationId}; treating as ${
302 cached ? "last known" : "not exempt"
303 }:`,
304 error,
305 );
306 });
307 yield* captureCauseEffect(error);
308 return cached?.exempt ?? false;
309 }),
310 ),
311 );
312 });
313
314 const decide = (organizationId: string): Effect.Effect<GateDecision> =>
315 Effect.suspend(() => {

Callers 1

decideFunction · 0.85

Calls 5

captureCauseEffectFunction · 0.90
writeExemptionCacheFunction · 0.85
warnMethod · 0.80
getMethod · 0.65
syncMethod · 0.65

Tested by

no test coverage detected