Skip to content

Commit 3ca0c15

Browse files
authored
Add ability to disable metadata flushing and logging (#1587)
1 parent 0aa5971 commit 3ca0c15

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

apps/webapp/app/env.server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const EnvironmentSchema = z.object({
5252
SMTP_PORT: z.coerce.number().optional(),
5353
SMTP_SECURE: z.coerce.boolean().optional(),
5454
SMTP_USER: z.string().optional(),
55-
SMTP_PASSWORD: z.string().optional(),
55+
SMTP_PASSWORD: z.string().optional(),
5656

5757
PLAIN_API_KEY: z.string().optional(),
5858
RUNTIME_PLATFORM: z.enum(["docker-compose", "ecs", "local"]).default("local"),
@@ -210,8 +210,7 @@ const EnvironmentSchema = z.object({
210210
ALERT_SMTP_PORT: z.coerce.number().optional(),
211211
ALERT_SMTP_SECURE: z.coerce.boolean().optional(),
212212
ALERT_SMTP_USER: z.string().optional(),
213-
ALERT_SMTP_PASSWORD: z.string().optional(),
214-
213+
ALERT_SMTP_PASSWORD: z.string().optional(),
215214

216215
MAX_SEQUENTIAL_INDEX_FAILURE_COUNT: z.coerce.number().default(96),
217216

@@ -261,6 +260,8 @@ const EnvironmentSchema = z.object({
261260

262261
REALTIME_STREAM_VERSION: z.enum(["v1", "v2"]).default("v1"),
263262
BATCH_METADATA_OPERATIONS_FLUSH_INTERVAL_MS: z.coerce.number().int().default(1000),
263+
BATCH_METADATA_OPERATIONS_FLUSH_ENABLED: z.string().default("1"),
264+
BATCH_METADATA_OPERATIONS_FLUSH_LOGGING_ENABLED: z.string().default("1"),
264265
});
265266

266267
export type Environment = z.infer<typeof EnvironmentSchema>;

apps/webapp/app/services/metadata/updateMetadata.server.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export class UpdateMetadataService extends BaseService {
3030

3131
constructor(
3232
protected readonly _prisma: PrismaClientOrTransaction = prisma,
33-
private readonly flushIntervalMs: number = 5000
33+
private readonly flushIntervalMs: number = 5000,
34+
private readonly flushEnabled: boolean = true,
35+
private readonly flushLoggingEnabled: boolean = true
3436
) {
3537
super();
3638

@@ -39,6 +41,14 @@ export class UpdateMetadataService extends BaseService {
3941

4042
// Start a loop that periodically flushes buffered operations
4143
private _startFlushing() {
44+
if (!this.flushEnabled) {
45+
logger.info("[UpdateMetadataService] 🚽 Flushing disabled");
46+
47+
return;
48+
}
49+
50+
logger.info("[UpdateMetadataService] 🚽 Flushing started");
51+
4252
// Create a program that sleeps, then processes buffered ops
4353
const program = Effect.gen(this, function* (_) {
4454
while (true) {
@@ -50,9 +60,11 @@ export class UpdateMetadataService extends BaseService {
5060
this._bufferedOperations.clear();
5161

5262
yield* Effect.sync(() => {
53-
logger.debug(`[UpdateMetadataService] Flushing operations`, {
54-
operations: Object.fromEntries(currentOperations),
55-
});
63+
if (this.flushLoggingEnabled) {
64+
logger.debug(`[UpdateMetadataService] Flushing operations`, {
65+
operations: Object.fromEntries(currentOperations),
66+
});
67+
}
5668
});
5769

5870
// If we have operations, process them
@@ -87,10 +99,12 @@ export class UpdateMetadataService extends BaseService {
8799
}
88100

89101
yield* Effect.sync(() => {
90-
logger.debug(`[UpdateMetadataService] Processing operations for run`, {
91-
runId,
92-
operationsCount: processedOps.length,
93-
});
102+
if (this.flushLoggingEnabled) {
103+
logger.debug(`[UpdateMetadataService] Processing operations for run`, {
104+
runId,
105+
operationsCount: processedOps.length,
106+
});
107+
}
94108
});
95109

96110
// Update run with retry
@@ -410,5 +424,11 @@ export class UpdateMetadataService extends BaseService {
410424

411425
export const updateMetadataService = singleton(
412426
"update-metadata-service",
413-
() => new UpdateMetadataService(prisma, env.BATCH_METADATA_OPERATIONS_FLUSH_INTERVAL_MS)
427+
() =>
428+
new UpdateMetadataService(
429+
prisma,
430+
env.BATCH_METADATA_OPERATIONS_FLUSH_INTERVAL_MS,
431+
env.BATCH_METADATA_OPERATIONS_FLUSH_ENABLED === "1",
432+
env.BATCH_METADATA_OPERATIONS_FLUSH_LOGGING_ENABLED === "1"
433+
)
414434
);

0 commit comments

Comments
 (0)