@@ -15,7 +15,7 @@ import assertNever from "assert-never";
1515import { AuthenticatedEnvironment } from "~/services/apiAuth.server" ;
1616import { generatePresignedUrl } from "~/v3/r2.server" ;
1717import { BasePresenter } from "./basePresenter.server" ;
18- import { prisma } from "~/db.server" ;
18+ import { $replica , prisma } from "~/db.server" ;
1919
2020// Build 'select' object
2121const commonRunSelect = {
@@ -59,48 +59,46 @@ type CommonRelatedRun = Prisma.Result<
5959 "findFirstOrThrow"
6060> ;
6161
62+ type FoundRun = NonNullable < Awaited < ReturnType < typeof ApiRetrieveRunPresenter . findRun > > > ;
63+
6264export class ApiRetrieveRunPresenter extends BasePresenter {
63- public async call (
64- friendlyId : string ,
65- env : AuthenticatedEnvironment
66- ) : Promise < RetrieveRunResponse | undefined > {
67- return this . traceWithEnv ( "call" , env , async ( span ) => {
68- const taskRun = await this . _replica . taskRun . findFirst ( {
69- where : {
70- friendlyId,
71- runtimeEnvironmentId : env . id ,
72- } ,
73- include : {
74- attempts : true ,
75- lockedToVersion : true ,
76- schedule : true ,
77- tags : true ,
78- batch : {
79- select : {
80- id : true ,
81- friendlyId : true ,
82- } ,
65+ public static async findRun ( friendlyId : string , env : AuthenticatedEnvironment ) {
66+ return $replica . taskRun . findFirst ( {
67+ where : {
68+ friendlyId,
69+ runtimeEnvironmentId : env . id ,
70+ } ,
71+ include : {
72+ attempts : true ,
73+ lockedToVersion : true ,
74+ schedule : true ,
75+ tags : true ,
76+ batch : {
77+ select : {
78+ id : true ,
79+ friendlyId : true ,
8380 } ,
84- parentTaskRun : {
85- select : commonRunSelect ,
86- } ,
87- rootTaskRun : {
88- select : commonRunSelect ,
89- } ,
90- childRuns : {
91- select : {
92- ... commonRunSelect ,
93- } ,
81+ } ,
82+ parentTaskRun : {
83+ select : commonRunSelect ,
84+ } ,
85+ rootTaskRun : {
86+ select : commonRunSelect ,
87+ } ,
88+ childRuns : {
89+ select : {
90+ ... commonRunSelect ,
9491 } ,
9592 } ,
96- } ) ;
97-
98- if ( ! taskRun ) {
99- logger . debug ( "Task run not found" , { friendlyId, envId : env . id } ) ;
100-
101- return undefined ;
102- }
93+ } ,
94+ } ) ;
95+ }
10396
97+ public async call (
98+ taskRun : FoundRun ,
99+ env : AuthenticatedEnvironment
100+ ) : Promise < RetrieveRunResponse | undefined > {
101+ return this . traceWithEnv ( "call" , env , async ( span ) => {
104102 let $payload : any ;
105103 let $payloadPresignedUrl : string | undefined ;
106104 let $output : any ;
0 commit comments