Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .server-changes/disable-postgres-task-event-writes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: feature
---

Added `EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED` to skip all PostgreSQL task-event writes for deployments that store task events in ClickHouse. Leave it off unless `EVENT_REPOSITORY_DEFAULT_STORE` is `clickhouse_v2`, otherwise task events are lost.
1 change: 1 addition & 0 deletions apps/webapp/app/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ const EnvironmentSchema = z
.enum(["postgres", "clickhouse", "clickhouse_v2"])
.default("postgres"),
EVENT_REPOSITORY_DEBUG_LOGS_DISABLED: BoolEnv.default(false),
EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED: BoolEnv.default(false),
EVENTS_CLICKHOUSE_MAX_TRACE_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(25_000),
EVENTS_CLICKHOUSE_MAX_TRACE_DETAILED_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(5_000),
EVENTS_CLICKHOUSE_MAX_LIVE_RELOADING_SETTING: z.coerce.number().int().default(2000),
Expand Down
13 changes: 11 additions & 2 deletions apps/webapp/app/v3/eventRepository/eventRepository.server.ts
Comment thread
ericallam marked this conversation as resolved.
Comment thread
ericallam marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,23 @@ export class EventRepository implements IEventRepository {
}

private async insertImmediate(event: CreateEventInput) {
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
return;
}
Comment thread
ericallam marked this conversation as resolved.
await this.#flushBatch(nanoid(), [this.#createableEventToPrismaEvent(event)]);
}

insertMany(events: CreateEventInput[]) {
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
return;
}
this._flushScheduler.addToBatch(events.map(this.#createableEventToPrismaEvent));
}

async insertManyImmediate(events: CreateEventInput[]) {
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
return;
}
Comment thread
ericallam marked this conversation as resolved.
await this.#flushBatchWithReturn(nanoid(), events.map(this.#createableEventToPrismaEvent));
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Expand Down Expand Up @@ -1018,7 +1027,7 @@ export class EventRepository implements IEventRepository {
if (options.immediate) {
await this.insertImmediate(event);
} else {
this._flushScheduler.addToBatch([this.#createableEventToPrismaEvent(event)]);
this.insertMany([event]);
}
}

Expand Down Expand Up @@ -1152,7 +1161,7 @@ export class EventRepository implements IEventRepository {
if (options.immediate) {
await this.insertImmediate(event);
} else {
this._flushScheduler.addToBatch([this.#createableEventToPrismaEvent(event)]);
this.insertMany([event]);
}

return result;
Expand Down
1 change: 1 addition & 0 deletions docs/self-hosting/env/webapp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ mode: "wide"
| `SERVER_OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` | No | 8192 | OTel span attribute value length limit. |
| **Task events** | | | |
| `EVENT_REPOSITORY_DEFAULT_STORE` | No | postgres | Where to store task events. Set to `clickhouse_v2` to store in ClickHouse (recommended for production). |
| `EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED` | No | 0 | Skip all PostgreSQL task-event writes (set to `1`). Only enable when `EVENT_REPOSITORY_DEFAULT_STORE` is `clickhouse_v2`, otherwise task events are lost. |
| **Realtime** | | | |
| `REALTIME_STREAM_VERSION` | No | v1 | Stream version exposed to tasks via the `TRIGGER_REALTIME_STREAM_VERSION` variable. Distinct from `REALTIME_STREAMS_DEFAULT_VERSION`. One of `v1`, `v2`. |
| `REALTIME_STREAM_MAX_LENGTH` | No | 1000 | Realtime stream max length. |
Expand Down
Loading