|
1 | | -import { type Prisma, type PrismaClient } from "@trigger.dev/database"; |
| 1 | +import { type Prisma, type PrismaClient, type PrismaClientOrTransaction } from "@trigger.dev/database"; |
| 2 | +import type { RunStore } from "@internal/run-store"; |
2 | 3 | import { BoundedTtlCache } from "./boundedTtlCache"; |
3 | 4 | import { RESERVED_COLUMNS, type RealtimeRunRow } from "./electricStreamProtocol.server"; |
4 | 5 |
|
@@ -79,6 +80,8 @@ export interface RunListResolver { |
79 | 80 | export type RunHydratorOptions = { |
80 | 81 | /** A read-replica Prisma client (`$replica`). Always Postgres. */ |
81 | 82 | replica: Pick<PrismaClient, "taskRun">; |
| 83 | + /** RunStore the reads are routed through; `replica` is passed as the read client. */ |
| 84 | + runStore: RunStore; |
82 | 85 | /** Read-through cache TTL (ms) collapsing duplicate refetches for the same run. Set 0 to disable. Defaults to 250ms. */ |
83 | 86 | cacheTtlMs?: number; |
84 | 87 | /** Hard cap on cache entries before expired entries are swept. */ |
@@ -139,24 +142,28 @@ export class RunHydrator { |
139 | 142 | if (ids.length === 0) { |
140 | 143 | return []; |
141 | 144 | } |
142 | | - const rows = await this.options.replica.taskRun.findMany({ |
143 | | - where: { |
144 | | - runtimeEnvironmentId: environmentId, |
145 | | - id: { in: ids }, |
| 145 | + const rows = await this.options.runStore.findRuns( |
| 146 | + { |
| 147 | + where: { |
| 148 | + runtimeEnvironmentId: environmentId, |
| 149 | + id: { in: ids }, |
| 150 | + }, |
| 151 | + select: buildHydratorSelect(skipColumns), |
146 | 152 | }, |
147 | | - select: buildHydratorSelect(skipColumns), |
148 | | - }); |
| 153 | + this.options.replica as PrismaClientOrTransaction |
| 154 | + ); |
149 | 155 | return rows as unknown as RealtimeRunRow[]; |
150 | 156 | } |
151 | 157 |
|
152 | 158 | async #fetch(environmentId: string, runId: string): Promise<RealtimeRunRow | null> { |
153 | | - const run = await this.options.replica.taskRun.findFirst({ |
154 | | - where: { |
| 159 | + const run = await this.options.runStore.findRun( |
| 160 | + { |
155 | 161 | id: runId, |
156 | 162 | runtimeEnvironmentId: environmentId, |
157 | 163 | }, |
158 | | - select: RUN_HYDRATOR_SELECT, |
159 | | - }); |
| 164 | + { select: RUN_HYDRATOR_SELECT }, |
| 165 | + this.options.replica as PrismaClientOrTransaction |
| 166 | + ); |
160 | 167 |
|
161 | 168 | return (run ?? null) as RealtimeRunRow | null; |
162 | 169 | } |
|
0 commit comments