Skip to content

Commit 59f99cf

Browse files
committed
Use an env var for the realtime maximum createdAt filter duration (defaults to 1 day)
1 parent eb957a6 commit 59f99cf

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

apps/webapp/app/env.server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ const EnvironmentSchema = z.object({
164164
.default(process.env.REDIS_TLS_DISABLED ?? "false"),
165165
REALTIME_STREAMS_REDIS_CLUSTER_MODE_ENABLED: z.string().default("0"),
166166

167+
REALTIME_MAXIMUM_CREATED_AT_FILTER_AGE_IN_MS: z.coerce
168+
.number()
169+
.int()
170+
.default(24 * 60 * 60 * 1000), // 1 day in milliseconds
171+
167172
PUBSUB_REDIS_HOST: z
168173
.string()
169174
.optional()

apps/webapp/app/services/realtimeClient.server.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import { jumpHash } from "@trigger.dev/core/v3/serverOnly";
1010
import { Cache, createCache, DefaultStatefulContext, Namespace } from "@unkey/cache";
1111
import { MemoryStore } from "@unkey/cache/stores";
1212
import { RedisCacheStore } from "./unkey/redisCacheStore.server";
13+
import { env } from "~/env.server";
1314

1415
export interface CachedLimitProvider {
1516
getCachedLimit: (organizationId: string, defaultValue: number) => Promise<number | undefined>;
1617
}
1718

18-
const MAXIMUM_CREATED_AT_FILTER_AGE_IN_MS = 7 * 24 * 60 * 60 * 1000;
19-
2019
const DEFAULT_ELECTRIC_COLUMNS = [
2120
"id",
2221
"taskIdentifier",
@@ -195,13 +194,13 @@ export class RealtimeClient {
195194
// This means we need to calculate the createdAt filter and store it in redis after we get back the response
196195
const createdAtFilter = safeParseNaturalLanguageDurationAgo(duration);
197196

198-
// Validate that the createdAt filter is in the past, and not more than 1 week in the past.
199-
// if it's more than 1 week in the past, just return 1 week ago Date
197+
// Validate that the createdAt filter is in the past, and not more than the maximum age in the past.
198+
// if it's more than the maximum age in the past, just return the maximum age in the past Date
200199
if (
201200
createdAtFilter &&
202-
createdAtFilter < new Date(Date.now() - MAXIMUM_CREATED_AT_FILTER_AGE_IN_MS)
201+
createdAtFilter < new Date(Date.now() - env.REALTIME_MAXIMUM_CREATED_AT_FILTER_AGE_IN_MS)
203202
) {
204-
return new Date(Date.now() - MAXIMUM_CREATED_AT_FILTER_AGE_IN_MS);
203+
return new Date(Date.now() - env.REALTIME_MAXIMUM_CREATED_AT_FILTER_AGE_IN_MS);
205204
}
206205

207206
return createdAtFilter;

0 commit comments

Comments
 (0)