@@ -7,12 +7,13 @@ import {
77import { type Project , type RuntimeEnvironment , type TaskRunStatus } from "@trigger.dev/database" ;
88import assertNever from "assert-never" ;
99import { z } from "zod" ;
10+ import { clickhouseClient } from "~/services/clickhouseInstance.server" ;
1011import { logger } from "~/services/logger.server" ;
1112import { CoercedDate } from "~/utils/zod" ;
13+ import { ServiceValidationError } from "~/v3/services/baseService.server" ;
1214import { ApiRetrieveRunPresenter } from "./ApiRetrieveRunPresenter.server" ;
13- import { type RunListOptions , RunListPresenter } from "./RunListPresenter .server" ;
15+ import { NextRunListPresenter , type RunListOptions } from "./NextRunListPresenter .server" ;
1416import { BasePresenter } from "./basePresenter.server" ;
15- import { ServiceValidationError } from "~/v3/services/baseService.server" ;
1617
1718export const ApiRunListSearchParams = z . object ( {
1819 "page[size]" : z . coerce . number ( ) . int ( ) . positive ( ) . min ( 1 ) . max ( 100 ) . optional ( ) ,
@@ -136,10 +137,12 @@ export class ApiRunListPresenter extends BasePresenter {
136137 }
137138
138139 let environmentId : string | undefined ;
140+ let organizationId : string | undefined ;
139141
140142 // filters
141143 if ( environment ) {
142144 environmentId = environment . id ;
145+ organizationId = environment . organizationId ;
143146 } else {
144147 if ( searchParams [ "filter[env]" ] ) {
145148 const environments = await this . _prisma . runtimeEnvironment . findMany ( {
@@ -152,13 +155,18 @@ export class ApiRunListPresenter extends BasePresenter {
152155 } ) ;
153156
154157 environmentId = environments . at ( 0 ) ?. id ;
158+ organizationId = environments . at ( 0 ) ?. organizationId ;
155159 }
156160 }
157161
158162 if ( ! environmentId ) {
159163 throw new ServiceValidationError ( "No environment found" ) ;
160164 }
161165
166+ if ( ! organizationId ) {
167+ throw new ServiceValidationError ( "No organization found" ) ;
168+ }
169+
162170 if ( searchParams [ "filter[status]" ] ) {
163171 options . statuses = searchParams [ "filter[status]" ] . flatMap ( ( status ) =>
164172 ApiRunListPresenter . apiStatusToRunStatuses ( status )
@@ -205,11 +213,15 @@ export class ApiRunListPresenter extends BasePresenter {
205213 options . batchId = searchParams [ "filter[batch]" ] ;
206214 }
207215
208- const presenter = new RunListPresenter ( ) ;
216+ if ( ! clickhouseClient ) {
217+ throw new Error ( "Clickhouse is not supported yet" ) ;
218+ }
219+
220+ const presenter = new NextRunListPresenter ( this . _prisma , clickhouseClient ) ;
209221
210222 logger . debug ( "Calling RunListPresenter" , { options } ) ;
211223
212- const results = await presenter . call ( environmentId , options ) ;
224+ const results = await presenter . call ( organizationId , environmentId , options ) ;
213225
214226 logger . debug ( "RunListPresenter results" , { runs : results . runs . length } ) ;
215227
0 commit comments