( taskId: string, maxBytes: number = DEFAULT_MAX_READ_BYTES, )
| 336 | * Caps at maxBytes to avoid loading multi-GB files into memory. |
| 337 | */ |
| 338 | export async function getTaskOutput( |
| 339 | taskId: string, |
| 340 | maxBytes: number = DEFAULT_MAX_READ_BYTES, |
| 341 | ): Promise<string> { |
| 342 | try { |
| 343 | const { content, bytesTotal, bytesRead } = await tailFile( |
| 344 | getTaskOutputPath(taskId), |
| 345 | maxBytes, |
| 346 | ) |
| 347 | if (bytesTotal > bytesRead) { |
| 348 | return `[${Math.round((bytesTotal - bytesRead) / 1024)}KB of earlier output omitted]\n${content}` |
| 349 | } |
| 350 | return content |
| 351 | } catch (e) { |
| 352 | const code = getErrnoCode(e) |
| 353 | if (code === 'ENOENT') { |
| 354 | return '' |
| 355 | } |
| 356 | logError(e) |
| 357 | return '' |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Get the current size (offset) of a task's output file. |
no test coverage detected