(config, state, job)
| 219 | } |
| 220 | |
| 221 | async function handleJob(config, state, job) { |
| 222 | if (job.type === "allocate") { |
| 223 | if ( |
| 224 | state.activeSessions.size + state.inFlightAllocations >= |
| 225 | config.maxCapacity |
| 226 | ) { |
| 227 | return; |
| 228 | } |
| 229 | state.inFlightAllocations += 1; |
| 230 | try { |
| 231 | await allocateSession(config, state, job); |
| 232 | } finally { |
| 233 | state.inFlightAllocations = Math.max(0, state.inFlightAllocations - 1); |
| 234 | } |
| 235 | } else if (job.type === "release") { |
| 236 | await releaseSession(config, state, job); |
| 237 | } else { |
| 238 | await completeJob(config, job.id, { |
| 239 | error: `Unsupported provider job type: ${job.type}`, |
| 240 | status: "failed", |
| 241 | }); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | async function allocateSession(config, state, job) { |
| 246 | const payload = job.payload || {}; |
no test coverage detected