(
environmentId: string,
environmentSecret: string,
signal?: AbortSignal,
reclaimOlderThanMs?: number,
)
| 197 | }, |
| 198 | |
| 199 | async pollForWork( |
| 200 | environmentId: string, |
| 201 | environmentSecret: string, |
| 202 | signal?: AbortSignal, |
| 203 | reclaimOlderThanMs?: number, |
| 204 | ): Promise<WorkResponse | null> { |
| 205 | validateBridgeId(environmentId, 'environmentId') |
| 206 | |
| 207 | // Save and reset so errors break the "consecutive empty" streak. |
| 208 | // Restored below when the response is truly empty. |
| 209 | const prevEmptyPolls = consecutiveEmptyPolls |
| 210 | consecutiveEmptyPolls = 0 |
| 211 | |
| 212 | const response = await axios.get<WorkResponse | null>( |
| 213 | `${deps.baseUrl}/v1/environments/${environmentId}/work/poll`, |
| 214 | { |
| 215 | headers: getHeaders(environmentSecret), |
| 216 | params: |
| 217 | reclaimOlderThanMs !== undefined |
| 218 | ? { reclaim_older_than_ms: reclaimOlderThanMs } |
| 219 | : undefined, |
| 220 | timeout: 10_000, |
| 221 | signal, |
| 222 | validateStatus: status => status < 500, |
| 223 | }, |
| 224 | ) |
| 225 | |
| 226 | handleErrorStatus(response.status, response.data, 'Poll') |
| 227 | |
| 228 | // Empty body or null = no work available |
| 229 | if (!response.data) { |
| 230 | consecutiveEmptyPolls = prevEmptyPolls + 1 |
| 231 | if ( |
| 232 | consecutiveEmptyPolls === 1 || |
| 233 | consecutiveEmptyPolls % EMPTY_POLL_LOG_INTERVAL === 0 |
| 234 | ) { |
| 235 | debug( |
| 236 | `[bridge:api] GET .../work/poll -> ${response.status} (no work, ${consecutiveEmptyPolls} consecutive empty polls)`, |
| 237 | ) |
| 238 | } |
| 239 | return null |
| 240 | } |
| 241 | |
| 242 | debug( |
| 243 | `[bridge:api] GET .../work/poll -> ${response.status} workId=${response.data.id} type=${response.data.data?.type}${response.data.data?.id ? ` sessionId=${response.data.data.id}` : ''}`, |
| 244 | ) |
| 245 | debug(`[bridge:api] <<< ${debugBody(response.data)}`) |
| 246 | return response.data |
| 247 | }, |
| 248 | |
| 249 | async acknowledgeWork( |
| 250 | environmentId: string, |
nothing calls this directly
no test coverage detected