Skip to content

Commit a29dd59

Browse files
committed
feat(webapp): add option to disable PostgreSQL task-event writes
Adds EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED (default off). When enabled, the task-event store skips all PostgreSQL writes, for deployments that store task events in ClickHouse (EVENT_REPOSITORY_DEFAULT_STORE=clickhouse_v2). Reads are unaffected, so existing events stay readable.
1 parent c235857 commit a29dd59

5 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: feature
4+
---
5+
6+
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.

apps/webapp/app/env.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,7 @@ const EnvironmentSchema = z
18281828
.enum(["postgres", "clickhouse", "clickhouse_v2"])
18291829
.default("postgres"),
18301830
EVENT_REPOSITORY_DEBUG_LOGS_DISABLED: BoolEnv.default(false),
1831+
EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED: BoolEnv.default(false),
18311832
EVENTS_CLICKHOUSE_MAX_TRACE_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(25_000),
18321833
EVENTS_CLICKHOUSE_MAX_TRACE_DETAILED_SUMMARY_VIEW_COUNT: z.coerce.number().int().default(5_000),
18331834
EVENTS_CLICKHOUSE_MAX_LIVE_RELOADING_SETTING: z.coerce.number().int().default(2000),

apps/webapp/app/v3/eventRepository/eventRepository.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ export class EventRepository implements IEventRepository {
120120
this._tracer = _config.tracer ?? trace.getTracer("eventRepo", "0.0.1");
121121

122122
// Instantiate the store using the partitioning flag.
123-
this.taskEventStore = new TaskEventStore(db, readReplica);
123+
this.taskEventStore = new TaskEventStore(
124+
db,
125+
readReplica,
126+
env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED
127+
);
124128
}
125129

126130
#createableEventToPrismaEvent(event: CreateEventInput): Prisma.TaskEventCreateManyInput {

apps/webapp/app/v3/taskEventStore.server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ export function getTaskEventStore(): TaskEventStoreTable {
5959
export class TaskEventStore {
6060
constructor(
6161
private db: PrismaClient,
62-
private readReplica: PrismaReplicaClient
62+
private readReplica: PrismaReplicaClient,
63+
private writesDisabled: boolean = false
6364
) {}
6465

6566
/**
6667
* Insert one record.
6768
*/
6869
async create(table: TaskEventStoreTable, data: Prisma.TaskEventCreateInput) {
70+
if (this.writesDisabled) {
71+
return;
72+
}
6973
if (table === "taskEventPartitioned") {
7074
return await this.db.taskEventPartitioned.create({ data });
7175
} else {
@@ -77,6 +81,9 @@ export class TaskEventStore {
7781
* Insert many records.
7882
*/
7983
async createMany(table: TaskEventStoreTable, data: Prisma.TaskEventCreateManyInput[]) {
84+
if (this.writesDisabled) {
85+
return { count: 0 };
86+
}
8087
if (table === "taskEventPartitioned") {
8188
return await this.db.taskEventPartitioned.createMany({ data });
8289
} else {

docs/self-hosting/env/webapp.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ mode: "wide"
135135
| `SERVER_OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` | No | 8192 | OTel span attribute value length limit. |
136136
| **Task events** | | | |
137137
| `EVENT_REPOSITORY_DEFAULT_STORE` | No | postgres | Where to store task events. Set to `clickhouse_v2` to store in ClickHouse (recommended for production). |
138+
| `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. |
138139
| **Realtime** | | | |
139140
| `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`. |
140141
| `REALTIME_STREAM_MAX_LENGTH` | No | 1000 | Realtime stream max length. |

0 commit comments

Comments
 (0)