MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / tryFlush

Method tryFlush

packages/db/src/buffers/base-buffer.ts:378–488  ·  view source on GitHub ↗
(options: { trigger?: FlushTrigger } = {})

Source from the content-addressed store, hash-verified

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

Callers 6

addMethod · 0.80
addMethod · 0.80
addMethod · 0.80
persistMethod · 0.80
addMethod · 0.80
cronJobFunction · 0.80

Calls 6

getBufferSizeMethod · 0.95
emitFlushObservationMethod · 0.95
releaseLockMethod · 0.95
generateSecureIdFunction · 0.90
getRedisCacheFunction · 0.90
setMethod · 0.45

Tested by

no test coverage detected