Skip to content

Commit defb105

Browse files
author
ci bot
committed
Merge branch 'aarthy/run-duration' into 'enterprise'
fix(runs): duration display incorrect when > 24 hours See merge request dkinternal/testgen/dataops-testgen!296
2 parents 83cedfc + 6a54f2e commit defb105

6 files changed

Lines changed: 24 additions & 17 deletions

File tree

testgen/common/models/profiling_run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class ProfilingRunMinimal(EntityMinimal):
3333
class ProfilingRunSummary(EntityMinimal):
3434
profiling_run_id: UUID
3535
start_time: datetime
36+
end_time: datetime
3637
table_groups_name: str
3738
status: ProfilingRunStatus
3839
process_id: int
39-
duration: str
4040
log_message: str
4141
schema_name: str
4242
table_ct: int
@@ -177,10 +177,10 @@ def select_summary(
177177
)
178178
SELECT v_profiling_runs.profiling_run_id,
179179
v_profiling_runs.start_time,
180+
v_profiling_runs.end_time,
180181
v_profiling_runs.table_groups_name,
181182
v_profiling_runs.status,
182183
v_profiling_runs.process_id,
183-
v_profiling_runs.duration,
184184
v_profiling_runs.log_message,
185185
v_profiling_runs.schema_name,
186186
v_profiling_runs.table_ct,

testgen/common/models/test_run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class TestRunMinimal(EntityMinimal):
3333
class TestRunSummary(EntityMinimal):
3434
test_run_id: UUID
3535
test_starttime: datetime
36+
test_endtime: datetime
3637
table_groups_name: str
3738
test_suite: str
3839
status: TestRunStatus
39-
duration: str
4040
process_id: int
4141
log_message: str
4242
test_ct: int
@@ -174,10 +174,10 @@ def select_summary(
174174
)
175175
SELECT test_runs.id AS test_run_id,
176176
test_runs.test_starttime,
177+
test_runs.test_endtime,
177178
table_groups.table_groups_name,
178179
test_suites.test_suite,
179180
test_runs.status,
180-
test_runs.duration,
181181
test_runs.process_id,
182182
test_runs.log_message,
183183
test_runs.test_ct,

testgen/template/dbsetup/060_create_standard_views.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ SELECT r.id as profiling_run_id,
6464
tg.table_groups_name,
6565
tg.table_group_schema as schema_name,
6666
r.profiling_starttime as start_time,
67-
TO_CHAR(r.profiling_endtime - r.profiling_starttime, 'HH24:MI:SS') as duration,
67+
r.profiling_endtime as end_time,
6868
r.status,
6969
r.log_message,
7070
r.table_ct,

testgen/ui/components/frontend/js/display_utils.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
function formatTimestamp(
22
/** @type number | string */ timestamp,
3-
/** @type boolean */ show_year,
3+
/** @type boolean */ showYear,
44
) {
55
if (timestamp) {
66
const date = new Date(typeof timestamp === 'number' ? timestamp * 1000 : timestamp);
77
if (!isNaN(date)) {
88
const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
99
const hours = date.getHours();
1010
const minutes = date.getMinutes();
11-
return `${months[date.getMonth()]} ${date.getDate()}, ${show_year ? date.getFullYear() + ' at ': ''}${(hours % 12) || 12}:${String(minutes).padStart(2, '0')} ${hours / 12 >= 1 ? 'PM' : 'AM'}`;
11+
return `${months[date.getMonth()]} ${date.getDate()}, ${showYear ? date.getFullYear() + ' at ': ''}${(hours % 12) || 12}:${String(minutes).padStart(2, '0')} ${hours / 12 >= 1 ? 'PM' : 'AM'}`;
1212
}
1313
}
1414
return '--';
1515
}
1616

17-
function formatDuration(/** @type string */ duration) {
18-
if (!duration) {
17+
function formatDuration(
18+
/** @type Date | number | string */ startTime,
19+
/** @type Date | number | string */ endTime,
20+
) {
21+
if (!startTime || !endTime) {
1922
return '--';
2023
}
2124

22-
const [ hour, minute, second ] = duration.split(':');
25+
const startDate = new Date(typeof startTime === 'number' ? startTime * 1000 : startTime);
26+
const endDate = new Date(typeof endTime === 'number' ? endTime * 1000 : endTime);
27+
const totalSeconds = Math.floor((endDate.getTime() - startDate.getTime()) / 1000);
28+
2329
let formatted = [
24-
{ value: Number(hour), unit: 'h' },
25-
{ value: Number(minute), unit: 'm' },
26-
{ value: Number(second), unit: 's' },
30+
{ value: Math.floor(totalSeconds / (3600 * 24)), unit: 'd' },
31+
{ value: Math.floor((totalSeconds % (3600 * 24)) / 3600), unit: 'h' },
32+
{ value: Math.floor((totalSeconds % 3600) / 60), unit: 'm' },
33+
{ value: totalSeconds % 60, unit: 's' },
2734
].map(({ value, unit }) => value ? `${value}${unit}` : '')
2835
.join(' ');
2936

testgen/ui/components/frontend/js/pages/profiling_runs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* @type {object}
44
* @property {string} profiling_run_id
55
* @property {number} start_time
6+
* @property {number} end_time
67
* @property {string} table_groups_name
78
* @property {'Running'|'Complete'|'Error'|'Cancelled'} status
89
* @property {string} log_message
9-
* @property {string} duration
1010
* @property {string} process_id
1111
* @property {string} schema_name
1212
* @property {number} column_ct
@@ -191,7 +191,7 @@ const ProfilingRunItem = (
191191
ProfilingRunStatus(item),
192192
div(
193193
{ class: 'text-caption mt-1', 'data-testid': 'profiling-run-item-duration' },
194-
formatDuration(item.duration),
194+
formatDuration(item.start_time, item.end_time),
195195
),
196196
),
197197
item.status === 'Running' && item.process_id && userCanRun ? Button({

testgen/ui/components/frontend/js/pages/test_runs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* @type {object}
44
* @property {string} test_run_id
55
* @property {number} test_starttime
6+
* @property {number} test_endtime
67
* @property {string} table_groups_name
78
* @property {string} test_suite
89
* @property {'Running'|'Complete'|'Error'|'Cancelled'} status
910
* @property {string} log_message
10-
* @property {string} duration
1111
* @property {string} process_id
1212
* @property {number} test_ct
1313
* @property {number} passed_ct
@@ -192,7 +192,7 @@ const TestRunItem = (
192192
TestRunStatus(item),
193193
div(
194194
{ class: 'text-caption mt-1' },
195-
formatDuration(item.duration),
195+
formatDuration(item.test_starttime, item.test_endtime),
196196
),
197197
),
198198
item.status === 'Running' && item.process_id && userCanRun ? Button({

0 commit comments

Comments
 (0)