@@ -15,7 +15,7 @@ import assertNever from "assert-never";
15
15
import { AuthenticatedEnvironment } from "~/services/apiAuth.server" ;
16
16
import { generatePresignedUrl } from "~/v3/r2.server" ;
17
17
import { BasePresenter } from "./basePresenter.server" ;
18
- import { prisma } from "~/db.server" ;
18
+ import { $replica , prisma } from "~/db.server" ;
19
19
20
20
// Build 'select' object
21
21
const commonRunSelect = {
@@ -59,48 +59,46 @@ type CommonRelatedRun = Prisma.Result<
59
59
"findFirstOrThrow"
60
60
> ;
61
61
62
+ type FoundRun = NonNullable < Awaited < ReturnType < typeof ApiRetrieveRunPresenter . findRun > > > ;
63
+
62
64
export 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 ,
83
80
} ,
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 ,
94
91
} ,
95
92
} ,
96
- } ) ;
97
-
98
- if ( ! taskRun ) {
99
- logger . debug ( "Task run not found" , { friendlyId, envId : env . id } ) ;
100
-
101
- return undefined ;
102
- }
93
+ } ,
94
+ } ) ;
95
+ }
103
96
97
+ public async call (
98
+ taskRun : FoundRun ,
99
+ env : AuthenticatedEnvironment
100
+ ) : Promise < RetrieveRunResponse | undefined > {
101
+ return this . traceWithEnv ( "call" , env , async ( span ) => {
104
102
let $payload : any ;
105
103
let $payloadPresignedUrl : string | undefined ;
106
104
let $output : any ;
0 commit comments