Skip to content

Commit

Permalink
improvement: improve replay autocleanup behavior to remove slices rig…
Browse files Browse the repository at this point in the history
…ht away after those were used
  • Loading branch information
thaaddeus committed Aug 12, 2022
1 parent 94537a8 commit b145a64
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/replay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createReadStream } from 'fs-extra'
import { createReadStream, remove } from 'fs-extra'
import path from 'path'
import { EventEmitter } from 'stream'
import { Worker } from 'worker_threads'
Expand Down Expand Up @@ -166,6 +166,10 @@ export async function* replay<T extends Exchange, U extends boolean = false, Z e

// remove slice key from the map as it's already processed
cachedSlicePaths.delete(sliceKey)

if (autoCleanup) {
await cleanupSlice(cachedSlicePath)
}
// move one minute forward
currentSliceDate.setUTCMinutes(currentSliceDate.getUTCMinutes() + 1)
}
Expand Down Expand Up @@ -209,6 +213,14 @@ export async function* replay<T extends Exchange, U extends boolean = false, Z e
}
}

async function cleanupSlice(slicePath: string) {
try {
await remove(slicePath)
} catch (e) {
debug('cleanupSlice error %s %o', slicePath, e)
}
}

// gracefully terminate worker
async function terminateWorker(worker: Worker, waitTimeout: number) {
let cancelWait = () => {}
Expand Down

0 comments on commit b145a64

Please sign in to comment.