diff --git a/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/models/stage_instance.ts b/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/models/stage_instance.ts index 1b30b981293..14c7a5abf1c 100644 --- a/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/models/stage_instance.ts +++ b/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/models/stage_instance.ts @@ -42,13 +42,13 @@ export class StageInstance { triggeredOn(): string { const LOCAL_TIME_FORMAT = "DD MMM, YYYY [at] HH:mm:ss"; - return moment.unix(this.stageScheduledTime()).format(LOCAL_TIME_FORMAT); + return moment.unix(this.stageCreatedTimeInSecs()).format(LOCAL_TIME_FORMAT); } triggeredOnServerTime(): string { const SERVER_TIME_FORMAT = "DD MMM, YYYY [at] HH:mm:ss Z [Server Time]"; const utcOffsetInMinutes = CONSTANTS.SERVER_TIMEZONE_UTC_OFFSET / 60000; - return moment.unix(this.stageScheduledTime()).utcOffset(utcOffsetInMinutes).format(SERVER_TIME_FORMAT); + return moment.unix(this.stageCreatedTimeInSecs()).utcOffset(utcOffsetInMinutes).format(SERVER_TIME_FORMAT); } stageDuration(): string { @@ -56,20 +56,8 @@ export class StageInstance { return `in progress`; } - // Prototype JS has overridden the original array reduce method. Use reduceRight instead. - // This fix is only required for the VSM page - // Do not change Array.prototype.reduce, as it will affect all the arrays from VSM page - // @ts-ignore - this.json.jobs.reduce = Array.prototype.reduceRight; - - // @ts-ignore - const highestJobTime = this.json.jobs.reduce((first: number, next: JobJSON) => { - const completed = next.job_state_transitions.find(t => t.state === "Completed")!; - return first < completed.state_change_time ? completed.state_change_time : first; - }, 0); - - const end = moment.unix(+highestJobTime / 1000); - const start = moment.unix(this.stageScheduledTime()); + const end = moment.unix(this.stageLastTransitionedTimeInSecs()); + const start = moment.unix(this.stageCreatedTimeInSecs()); return JobDurationStrategyHelper.formatTimeForDisplay(moment.utc(end.diff(start))); } @@ -124,11 +112,12 @@ export class StageInstance { return ApiRequestBuilder.POST(SparkRoutes.runStage(this.json.pipeline_name, this.json.pipeline_counter, this.json.name), ApiVersion.latest); } - stageScheduledTime(): number { - return this.json.jobs.reduce((minTime, next) => { - const jobScheduledTime = next.scheduled_date / 1000; - return minTime < jobScheduledTime ? minTime : jobScheduledTime; - }, Infinity); + stageCreatedTimeInSecs(): number { + return this.json.created_time / 1000; + } + + stageLastTransitionedTimeInSecs(): number { + return this.json.last_transitioned_time / 1000; } private isStageInProgress(): boolean { diff --git a/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/models/types.ts b/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/models/types.ts index 402cf906c2c..2072c747710 100644 --- a/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/models/types.ts +++ b/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/models/types.ts @@ -40,6 +40,8 @@ export interface StageInstanceJSON { counter: number; approval_type: string; approved_by: string; + created_time: number; + last_transitioned_time: number; cancelled_by?: string; result: Result | string; rerun_of_counter: number | null; diff --git a/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/spec/models/stage_instance_spec.ts b/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/spec/models/stage_instance_spec.ts index 2550c9c0a92..a866c07c54e 100644 --- a/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/spec/models/stage_instance_spec.ts +++ b/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/spec/models/stage_instance_spec.ts @@ -38,7 +38,7 @@ describe('Stage Instance', () => { it('should provide triggered on information', () => { const json: StageInstance = StageInstance.fromJSON(stageInstanceJson); - expect(json.triggeredOn()).toBe(TestData.unixTime(json.stageScheduledTime())); + expect(json.triggeredOn()).toBe(TestData.unixTime(json.stageCreatedTimeInSecs())); }); describe("Stage Duration", () => { diff --git a/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/spec/test_data.ts b/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/spec/test_data.ts index a31f58ceb7f..5badeae6fe4 100644 --- a/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/spec/test_data.ts +++ b/server/src/main/webapp/WEB-INF/rails/webpack/views/dashboard/stage_overview/spec/test_data.ts @@ -13,6 +13,8 @@ export class TestData { counter: 1, approval_type: "success", approved_by: "admin", + created_time: 1595825414079, + last_transitioned_time: 1595831464796, result: "Passed", rerun_of_counter: null, fetch_materials: true,