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