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

Function withPreExecutionGate

apps/cloud/src/engine/execution-gate.ts:78–107  ·  view source on GitHub ↗
(
  engine: ExecutionEngine<E>,
  decide: Effect.Effect<GateDecision>,
)

Source from the content-addressed store, hash-verified

76 * untouched: paused executions must always be able to complete.
77 */
78export const withPreExecutionGate = <E extends Cause.YieldableError>(
79 engine: ExecutionEngine<E>,
80 decide: Effect.Effect<GateDecision>,
81): ExecutionEngine<E> => ({
82 execute: (code, options) =>
83 Effect.flatMap(
84 decide,
85 (decision): Effect.Effect<EngineExecuteResult, E> =>
86 decision.blocked
87 ? Effect.succeed({ result: null, error: decision.error.message })
88 : engine.execute(code, options),
89 ),
90 executeWithPause: (code, options) =>
91 Effect.flatMap(
92 decide,
93 (decision): Effect.Effect<ExecutionResult, E> =>
94 decision.blocked
95 ? Effect.succeed({
96 status: "completed",
97 result: { result: null, error: decision.error.message },
98 })
99 : engine.executeWithPause(code, options),
100 ),
101 // resume is never gated: paused executions must be able to complete.
102 resume: (executionId, response) => engine.resume(executionId, response),
103 getPausedExecution: (executionId) => engine.getPausedExecution(executionId),
104 pausedExecutionCount: () => engine.pausedExecutionCount(),
105 hasPausedExecutions: () => engine.hasPausedExecutions(),
106 getDescription: engine.getDescription,
107});
108
109// ---------------------------------------------------------------------------
110// Balance gate factory

Callers 2

makeExecutionRateLimiterFunction · 0.90
makeExecutionLimitGateFunction · 0.85

Calls 1

executeMethod · 0.65

Tested by

no test coverage detected