Skip to content

Commit

Permalink
feat: batch cron size
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Sep 20, 2024
1 parent 93f9304 commit d03e90e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ const emailEnv = createEnv({
const dbEnv = createEnv({
server: {
UNDB_DB_PROVIDER: z.enum(["sqlite", "turso"]).default("sqlite").optional(),
UNDB_OUTBOX_SCAN_BATCH_SIZE: z
.string()
.optional()
.transform((v) => parseInt(v ?? "1000", 10)),
},
runtimeEnv: import.meta.env,
emptyStringAsUndefined: true,
Expand Down
7 changes: 6 additions & 1 deletion packages/realtime/src/reply/reply.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject, singleton } from "@undb/di"
import type { BaseEvent } from "@undb/domain"
import { env } from "@undb/env"
import type { IQueryBuilder } from "@undb/persistence/src/qb"
import { injectQueryBuilder } from "@undb/persistence/src/qb.provider"
import { PubSubContext } from "../pubsub/pubsub.context"
Expand All @@ -16,7 +17,11 @@ export class ReplyService {
) {}

public async scan() {
const outboxList = await this.qb.selectFrom("undb_outbox").selectAll().limit(10).execute()
const outboxList = await this.qb
.selectFrom("undb_outbox")
.selectAll()
.limit(env.UNDB_OUTBOX_SCAN_BATCH_SIZE)
.execute()
for (const item of outboxList) {
const event = ReplyEventFactory.from(item)
if (event.isNone()) continue
Expand Down

0 comments on commit d03e90e

Please sign in to comment.