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

Function resolveExemption

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

Source from the content-addressed store, hash-verified

197 * known-paid org into a block mid-workload.
198 */
199 const resolveExemption = (organizationId: string): Effect.Effect<boolean> =>
200 Effect.suspend(() => {
201 if (!isExempt) return Effect.succeed(false);
202 const nowMs = now();
203 const cached = exemptionCache.get(organizationId);
204 if (cached && cached.expiresAtMs > nowMs) return Effect.succeed(cached.exempt);
205 return isExempt(organizationId).pipe(
206 Effect.timeoutOrElse({
207 duration: `${EXEMPTION_CHECK_TIMEOUT_MS} millis`,
208 orElse: () =>
209 Effect.fail(new ExemptionCheckTimeoutError({ timeoutMs: EXEMPTION_CHECK_TIMEOUT_MS })),
210 }),
211 Effect.map((exempt) => {
212 writeExemptionCache(organizationId, exempt, nowMs);
213 return exempt;
214 }),
215 Effect.catch((error: unknown) =>
216 Effect.gen(function* () {
217 yield* Effect.sync(() => {
218 console.warn(
219 `[rate-limit] exemption lookup failed for ${organizationId}; treating as ${
220 cached ? "last known" : "not exempt"
221 }:`,
222 error,
223 );
224 });
225 yield* captureCauseEffect(error);
226 return cached?.exempt ?? false;
227 }),
228 ),
229 );
230 });
231
232 const decide = (organizationId: string): Effect.Effect<GateDecision> =>
233 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