(config, state)
| 192 | } |
| 193 | |
| 194 | async function pollJob(config, state) { |
| 195 | if ( |
| 196 | state.activeSessions.size + state.inFlightAllocations >= |
| 197 | config.maxCapacity |
| 198 | ) { |
| 199 | return; |
| 200 | } |
| 201 | const response = await studioJson( |
| 202 | config, |
| 203 | "/api/actions/provider-hosts/jobs/next", |
| 204 | { |
| 205 | hostId: config.hostId, |
| 206 | hostToken: config.hostToken, |
| 207 | }, |
| 208 | ); |
| 209 | if (!response?.job) { |
| 210 | return; |
| 211 | } |
| 212 | const task = handleJob(config, state, response.job).catch((error) => { |
| 213 | console.error( |
| 214 | `[simdeck-provider] job ${response.job.id} failed: ${describeError(error)}`, |
| 215 | ); |
| 216 | }); |
| 217 | state.activeRequests.add(task); |
| 218 | task.finally(() => state.activeRequests.delete(task)); |
| 219 | } |
| 220 | |
| 221 | async function handleJob(config, state, job) { |
| 222 | if (job.type === "allocate") { |
no test coverage detected