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

Function resolveExemption

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

Source from the content-addressed store, hash-verified

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