UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 2.02 kB
//!src/infra/backup-progress.ts const MIN_PROGRESS_INTERVAL_MS=15e3;const MAX_PROGRESS_LINES=80;const MAX_LARGE_START_LINES=20;const LARGE_DATABASE_BYTES=1024**3;function createBackupProgressLogger(e){const t=/* @__PURE__ */ new Map;let n=Number.NEGATIVE_INFINITY;let r=0;let i=0;let a=false;const write=t=>{try{e(t)}catch{}};const report=e=>{if(a)return;const o=Date.now();const s=e.phase===`start`&&!t.has(e.stage);const c=t.get(e.stage)??{elapsedMs:0,runs:0,bytes:0,outputBytes:0,currentBytes:0,currentOutputBytes:0};t.set(e.stage,c);if(e.phase===`start`){c.startedAt=o;c.currentBytes=0;c.currentOutputBytes=0}if(e.bytes!==void 0&&e.phase!==`start`)c.currentBytes=e.bytes;if(e.outputBytes!==void 0)c.currentOutputBytes=e.outputBytes;if(e.phase===`done`){c.runs+=1;c.bytes+=c.currentBytes;c.outputBytes+=c.currentOutputBytes;c.elapsedMs+=Math.max(0,o-(c.startedAt??o));c.startedAt=void 0}const l=e.phase===`start`&&(e.sourceBytes??0)>=LARGE_DATABASE_BYTES&&i<MAX_LARGE_START_LINES;if(!s&&!l&&(r>=MAX_PROGRESS_LINES||o-n<MIN_PROGRESS_INTERVAL_MS))return;const u=e.bytes===void 0?``:` bytes=${Math.max(0,e.bytes)}`;const d=e.sourceBytes===void 0?``:` sourceBytes=${Math.max(0,e.sourceBytes)}`;const f=e.totalBytes===void 0?``:` totalBytes=${Math.max(0,e.totalBytes)}`;const p=e.outputBytes===void 0?``:` outputBytes=${Math.max(0,e.outputBytes)}`;const m=e.pages===void 0?``:` pages=${Math.max(0,e.pages)}`;const h=e.totalPages===void 0?``:` totalPages=${Math.max(0,e.totalPages)}`;write(`Backup progress: stage=${e.stage} phase=${e.phase}${u}${d}${f}${p}${m}${h}`);if(l)i+=1;else r+=1;n=o};const finish=()=>{if(a)return;a=true;const e=Date.now();for(const[n,r]of t){const t=r.startedAt!==void 0;const i=t?Math.max(0,e-r.startedAt):0;write(`Backup progress: stage=${n} phase=summary runs=${r.runs} bytes=${r.bytes+(t?r.currentBytes:0)} outputBytes=${r.outputBytes+(t?r.currentOutputBytes:0)} elapsedMs=${r.elapsedMs+i} complete=${!t}`)}};return Object.assign(report,{finish})}export{createBackupProgressLogger as t};