* Get the status of an async job * @param taskId The job ID returned from async execution
(taskId: string)
| 360 | * @param taskId The job ID returned from async execution |
| 361 | */ |
| 362 | async getJobStatus(taskId: string): Promise<JobStatusResult> { |
| 363 | const url = `${this.baseUrl}/api/jobs/${taskId}` |
| 364 | |
| 365 | try { |
| 366 | const response = await fetch(url, { |
| 367 | method: 'GET', |
| 368 | headers: { |
| 369 | 'X-API-Key': this.apiKey, |
| 370 | }, |
| 371 | }) |
| 372 | |
| 373 | this.updateRateLimitInfo(response) |
| 374 | |
| 375 | if (!response.ok) { |
| 376 | const errorData = (await response.json().catch(() => ({}))) as unknown as any |
| 377 | throw new SimStudioError( |
| 378 | errorData.error || `HTTP ${response.status}: ${response.statusText}`, |
| 379 | errorData.code, |
| 380 | response.status |
| 381 | ) |
| 382 | } |
| 383 | |
| 384 | const result = await response.json() |
| 385 | return result as JobStatusResult |
| 386 | } catch (error: any) { |
| 387 | if (error instanceof SimStudioError) { |
| 388 | throw error |
| 389 | } |
| 390 | |
| 391 | throw new SimStudioError(error?.message || 'Failed to get job status', 'STATUS_ERROR') |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Execute workflow with automatic retry on rate limit |
no test coverage detected