MCPcopy
hub / github.com/simstudioai/sim / enqueueExecution

Function enqueueExecution

apps/sim/lib/execution/isolated-vm.ts:1174–1259  ·  view source on GitHub ↗
(
  ownerState: OwnerState,
  req: IsolatedVMExecutionRequest,
  resolve: (result: IsolatedVMExecutionResult) => void,
  state: ExecutionState,
  brokers?: Record<string, IsolatedVMBrokerHandler>
)

Source from the content-addressed store, hash-verified

1172}
1173
1174function enqueueExecution(
1175 ownerState: OwnerState,
1176 req: IsolatedVMExecutionRequest,
1177 resolve: (result: IsolatedVMExecutionResult) => void,
1178 state: ExecutionState,
1179 brokers?: Record<string, IsolatedVMBrokerHandler>
1180) {
1181 if (queueLength() >= MAX_QUEUE_SIZE) {
1182 logger.warn('Isolated-vm saturation: global queue full', {
1183 reason: 'queue_full_global',
1184 queueLength: queueLength(),
1185 max: MAX_QUEUE_SIZE,
1186 totalActive: totalActiveExecutions,
1187 poolSize: workers.size,
1188 ownerKey: ownerState.ownerKey,
1189 })
1190 resolve({
1191 result: null,
1192 stdout: '',
1193 error: {
1194 message: 'Code execution is at capacity. Please try again in a moment.',
1195 name: 'Error',
1196 isSystemError: true,
1197 },
1198 })
1199 return
1200 }
1201 if (ownerState.queueLength >= MAX_QUEUED_PER_OWNER) {
1202 logger.warn('Isolated-vm saturation: per-owner queue full', {
1203 reason: 'queue_full_owner',
1204 ownerKey: ownerState.ownerKey,
1205 ownerQueueLength: ownerState.queueLength,
1206 ownerActive: ownerState.activeExecutions,
1207 max: MAX_QUEUED_PER_OWNER,
1208 })
1209 resolve({
1210 result: null,
1211 stdout: '',
1212 error: {
1213 message:
1214 'Too many concurrent code executions. Please wait for some to complete before running more.',
1215 name: 'Error',
1216 },
1217 })
1218 return
1219 }
1220
1221 const queueId = ++queueIdCounter
1222 const queueTimeout = setTimeout(() => {
1223 const queued = removeQueuedExecutionById(queueId)
1224 if (!queued) return
1225 logger.warn('Isolated-vm saturation: queue wait timeout', {
1226 reason: 'queue_wait_timeout',
1227 ownerKey: ownerState.ownerKey,
1228 queueTimeoutMs: QUEUE_TIMEOUT_MS,
1229 })
1230 resolve({
1231 result: null,

Callers 1

executeInIsolatedVMFunction · 0.85

Calls 7

queueLengthFunction · 0.85
pushQueuedExecutionFunction · 0.85
drainQueueFunction · 0.85
infoMethod · 0.80
warnMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected