(
executionId: string,
context: ExecutionEventWriterContext = {}
)
| 418 | } |
| 419 | |
| 420 | function createMemoryExecutionEventWriter( |
| 421 | executionId: string, |
| 422 | context: ExecutionEventWriterContext = {} |
| 423 | ): ExecutionEventWriter { |
| 424 | const writeMemoryEvent = async (event: ExecutionEvent) => { |
| 425 | const stream = getMemoryStream(executionId) |
| 426 | const compactEvent = await compactEventForBuffer(event, context) |
| 427 | const entry = { |
| 428 | eventId: stream.nextEventId++, |
| 429 | executionId, |
| 430 | event: compactEvent, |
| 431 | } |
| 432 | stream.events.push(entry) |
| 433 | if (stream.events.length > EVENT_LIMIT) { |
| 434 | stream.events = stream.events.slice(-EVENT_LIMIT) |
| 435 | const earliestEventId = stream.events[0]?.eventId |
| 436 | if (earliestEventId !== undefined && stream.meta) { |
| 437 | stream.meta = { |
| 438 | ...stream.meta, |
| 439 | earliestEventId, |
| 440 | updatedAt: new Date().toISOString(), |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | touchMemoryStream(stream) |
| 445 | return entry |
| 446 | } |
| 447 | |
| 448 | return { |
| 449 | write: writeMemoryEvent, |
| 450 | writeTerminal: async (event, status) => { |
| 451 | const entry = await writeMemoryEvent(event) |
| 452 | const stream = getMemoryStream(executionId) |
| 453 | stream.meta = { |
| 454 | ...stream.meta, |
| 455 | status, |
| 456 | updatedAt: new Date().toISOString(), |
| 457 | } |
| 458 | touchMemoryStream(stream) |
| 459 | return entry |
| 460 | }, |
| 461 | flush: async () => {}, |
| 462 | close: async () => {}, |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | export async function flushExecutionStreamReplayBuffer( |
| 467 | executionId: string, |
no test coverage detected