@@ -39,6 +39,7 @@ const commonRunSelect = {
3939 idempotencyKey : true ,
4040 isTest : true ,
4141 depth : true ,
42+ scheduleId : true ,
4243 lockedToVersion : {
4344 select : {
4445 version : true ,
@@ -71,7 +72,6 @@ export class ApiRetrieveRunPresenter extends BasePresenter {
7172 include : {
7273 attempts : true ,
7374 lockedToVersion : true ,
74- schedule : true ,
7575 tags : true ,
7676 batch : {
7777 select : {
@@ -157,20 +157,7 @@ export class ApiRetrieveRunPresenter extends BasePresenter {
157157 output : $output ,
158158 outputPresignedUrl : $outputPresignedUrl ,
159159 error : ApiRetrieveRunPresenter . apiErrorFromError ( taskRun . error ) ,
160- schedule : taskRun . schedule
161- ? {
162- id : taskRun . schedule . friendlyId ,
163- externalId : taskRun . schedule . externalId ?? undefined ,
164- deduplicationKey : taskRun . schedule . userProvidedDeduplicationKey
165- ? taskRun . schedule . deduplicationKey
166- : undefined ,
167- generator : {
168- type : "CRON" as const ,
169- expression : taskRun . schedule . generatorExpression ,
170- description : taskRun . schedule . generatorDescription ,
171- } ,
172- }
173- : undefined ,
160+ schedule : await resolveSchedule ( taskRun ) ,
174161 // We're removing attempts from the API
175162 attemptCount : taskRun . attempts . length ,
176163 attempts : [ ] ,
@@ -320,6 +307,33 @@ export class ApiRetrieveRunPresenter extends BasePresenter {
320307 }
321308}
322309
310+ async function resolveSchedule ( run : CommonRelatedRun ) {
311+ if ( ! run . scheduleId ) {
312+ return undefined ;
313+ }
314+
315+ const schedule = await prisma . taskSchedule . findFirst ( {
316+ where : {
317+ id : run . scheduleId ,
318+ } ,
319+ } ) ;
320+
321+ if ( ! schedule ) {
322+ return undefined ;
323+ }
324+
325+ return {
326+ id : schedule . friendlyId ,
327+ externalId : schedule . externalId ?? undefined ,
328+ deduplicationKey : schedule . userProvidedDeduplicationKey ? schedule . deduplicationKey : undefined ,
329+ generator : {
330+ type : "CRON" as const ,
331+ expression : schedule . generatorExpression ,
332+ description : schedule . generatorDescription ,
333+ } ,
334+ } ;
335+ }
336+
323337async function createCommonRunStructure ( run : CommonRelatedRun ) {
324338 const metadata = await parsePacket ( {
325339 data : run . metadata ?? undefined ,
0 commit comments