(options: { trigger?: FlushTrigger } = {})
| 376 | } |
| 377 | |
| 378 | async tryFlush(options: { trigger?: FlushTrigger } = {}) { |
| 379 | const trigger: FlushTrigger = options.trigger ?? 'cron'; |
| 380 | const startedAt = performance.now(); |
| 381 | this.inflightStats = {}; |
| 382 | |
| 383 | let llenAtStart: number | undefined; |
| 384 | try { |
| 385 | llenAtStart = await this.getBufferSize(); |
| 386 | } catch { |
| 387 | // best-effort |
| 388 | } |
| 389 | |
| 390 | const isCronQueuePaused = await cronQueue.isPaused(); |
| 391 | if (isCronQueuePaused) { |
| 392 | this.emitFlushObservation({ |
| 393 | buffer: this.name, |
| 394 | result: 'paused', |
| 395 | trigger, |
| 396 | totalMs: performance.now() - startedAt, |
| 397 | llenAtStart, |
| 398 | }); |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | if (this.enableParallelProcessing) { |
| 403 | const onFlushStarted = performance.now(); |
| 404 | try { |
| 405 | await this.onFlush(); |
| 406 | this.emitFlushObservation({ |
| 407 | buffer: this.name, |
| 408 | result: 'success', |
| 409 | trigger, |
| 410 | totalMs: performance.now() - startedAt, |
| 411 | rowsProcessed: this.inflightStats.rowsProcessed, |
| 412 | llenAtStart, |
| 413 | phases: { |
| 414 | ...this.inflightStats.phases, |
| 415 | onFlushMs: performance.now() - onFlushStarted, |
| 416 | }, |
| 417 | }); |
| 418 | } catch (error) { |
| 419 | this.emitFlushObservation({ |
| 420 | buffer: this.name, |
| 421 | result: 'error', |
| 422 | trigger, |
| 423 | totalMs: performance.now() - startedAt, |
| 424 | rowsProcessed: this.inflightStats.rowsProcessed, |
| 425 | llenAtStart, |
| 426 | phases: { |
| 427 | ...this.inflightStats.phases, |
| 428 | onFlushMs: performance.now() - onFlushStarted, |
| 429 | }, |
| 430 | err: error, |
| 431 | }); |
| 432 | } |
| 433 | return; |
| 434 | } |
| 435 |
no test coverage detected