Remove defaults and init

This commit is contained in:
Adria Navarro 2024-03-05 14:19:05 +01:00
parent b94d28b7d6
commit 8d87850765
2 changed files with 20 additions and 35 deletions

View File

@ -7,8 +7,6 @@ import { JobQueue, createQueue } from "../queue"
import * as context from "../context"
import * as dbUtils from "../db"
const DEFAULT_WRITE_RATE_MS = 10000
let CACHE: BaseCache | null = null
async function getCache() {
if (!CACHE) {
@ -29,11 +27,6 @@ export const docWritethroughProcessorQueue = createQueue<ProcessDocMessage>(
JobQueue.DOC_WRITETHROUGH_QUEUE
)
let _init = false
export const init = () => {
if (_init) {
return
}
docWritethroughProcessorQueue.process(async message => {
const { tenantId, cacheKeyPrefix } = message.data
await context.doInTenant(tenantId, async () => {
@ -46,6 +39,7 @@ export const init = () => {
},
async () => {
await persistToDb(message.data)
console.log("DocWritethrough persisted", { data: message.data })
}
)
@ -54,8 +48,6 @@ export const init = () => {
}
})
})
_init = true
}
export async function persistToDb({
dbName,
@ -97,11 +89,7 @@ export class DocWritethrough {
private cacheKeyPrefix: string
constructor(
db: Database,
docId: string,
writeRateMs: number = DEFAULT_WRITE_RATE_MS
) {
constructor(db: Database, docId: string, writeRateMs: number) {
this.db = db
this._docId = docId
this.writeRateMs = writeRateMs

View File

@ -5,7 +5,6 @@ import _ from "lodash"
import {
DocWritethrough,
docWritethroughProcessorQueue,
init,
} from "../docWritethrough"
import InMemoryQueue from "../../queue/inMemoryQueue"
@ -45,8 +44,6 @@ describe("docWritethrough", () => {
}, {} as Record<string, any>)
}
beforeAll(() => init())
beforeEach(async () => {
resetTime()
documentId = structures.uuid()