@@ -6,12 +6,14 @@ import { clickhouseFactory } from "~/services/clickhouse/clickhouseFactoryInstan
66import { nextScheduledTimestamps } from "~/v3/utils/calculateNextSchedule.server" ;
77import { NextRunListPresenter } from "./NextRunListPresenter.server" ;
88import { scheduleWhereClause } from "~/models/schedules.server" ;
9+ import { formatScheduleWindow } from "~/v3/scheduleWindow.server" ;
910
1011type ViewScheduleOptions = {
1112 userId ?: string ;
1213 projectId : string ;
1314 friendlyId : string ;
1415 environmentId : string ;
16+ includeRunHistory ?: boolean ;
1517} ;
1618
1719export class ViewSchedulePresenter {
@@ -21,7 +23,13 @@ export class ViewSchedulePresenter {
2123 this . #prismaClient = prismaClient ;
2224 }
2325
24- public async call ( { userId, projectId, friendlyId, environmentId } : ViewScheduleOptions ) {
26+ public async call ( {
27+ userId,
28+ projectId,
29+ friendlyId,
30+ environmentId,
31+ includeRunHistory = true ,
32+ } : ViewScheduleOptions ) {
2533 const schedule = await this . #prismaClient. taskSchedule . findFirst ( {
2634 select : {
2735 id : true ,
@@ -30,6 +38,8 @@ export class ViewSchedulePresenter {
3038 generatorExpression : true ,
3139 generatorDescription : true ,
3240 timezone : true ,
41+ windowDurationSeconds : true ,
42+ windowPercentage : true ,
3343 externalId : true ,
3444 deduplicationKey : true ,
3545 userProvidedDeduplicationKey : true ,
@@ -76,17 +86,14 @@ export class ViewSchedulePresenter {
7686 ? nextScheduledTimestamps ( schedule . generatorExpression , schedule . timezone , new Date ( ) , 5 )
7787 : [ ] ;
7888
79- const clickhouse = await clickhouseFactory . getClickhouseForOrganization (
80- schedule . project . organizationId ,
81- "standard"
82- ) ;
83- const runPresenter = new NextRunListPresenter ( this . #prismaClient, clickhouse ) ;
84- const { runs } = await runPresenter . call ( schedule . project . organizationId , environmentId , {
85- projectId : schedule . project . id ,
86- scheduleId : schedule . id ,
87- pageSize : 5 ,
88- period : "31d" ,
89- } ) ;
89+ const runs = includeRunHistory
90+ ? await this . #getRunHistory( {
91+ organizationId : schedule . project . organizationId ,
92+ environmentId,
93+ projectId : schedule . project . id ,
94+ scheduleId : schedule . id ,
95+ } )
96+ : [ ] ;
9097
9198 return {
9299 schedule : {
@@ -107,6 +114,32 @@ export class ViewSchedulePresenter {
107114 } ;
108115 }
109116
117+ async #getRunHistory( {
118+ organizationId,
119+ environmentId,
120+ projectId,
121+ scheduleId,
122+ } : {
123+ organizationId : string ;
124+ environmentId : string ;
125+ projectId : string ;
126+ scheduleId : string ;
127+ } ) {
128+ const clickhouse = await clickhouseFactory . getClickhouseForOrganization (
129+ organizationId ,
130+ "standard"
131+ ) ;
132+ const runPresenter = new NextRunListPresenter ( this . #prismaClient, clickhouse ) ;
133+ const { runs } = await runPresenter . call ( organizationId , environmentId , {
134+ projectId,
135+ scheduleId,
136+ pageSize : 5 ,
137+ period : "31d" ,
138+ } ) ;
139+
140+ return runs ;
141+ }
142+
110143 public toJSONResponse ( result : NonNullable < Awaited < ReturnType < ViewSchedulePresenter [ "call" ] > > > ) {
111144 const response : ScheduleObject = {
112145 id : result . schedule . friendlyId ,
@@ -120,6 +153,7 @@ export class ViewSchedulePresenter {
120153 description : result . schedule . cronDescription ,
121154 } ,
122155 timezone : result . schedule . timezone ,
156+ window : formatScheduleWindow ( result . schedule ) ,
123157 externalId : result . schedule . externalId ?? undefined ,
124158 deduplicationKey : result . schedule . userProvidedDeduplicationKey
125159 ? ( result . schedule . deduplicationKey ?? undefined )
0 commit comments