Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Support sorting by completionTime #5375

Merged
merged 4 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/rest-server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ info:
Version 2.2.1: a user can add/delete tags to/from his/her own jobs
version 2.2.2: add get task logs api
version 2.2.3: set .jobStatus.appId nullable in get jobAttempt schema
version 2.2.4: support sorting by completionTime in get the list of jobs
license:
name: MIT License
url: "https://github.com/microsoft/pai/blob/master/LICENSE"
Expand Down Expand Up @@ -1158,7 +1159,10 @@ paths:
type: number
- name: order
in: query
description: 'order of job list. It follows the format <field>,<ASC|DESC>, default value is "submissionTime,DESC". Available fields include: jobName, submissionTime, username, vc, retries, totalTaskNumber, totalGpuNumber, state'
description: 'order of job list.
It follows the format <field>,<ASC|DESC>, default value is "submissionTime,DESC".
Available fields include: jobName, submissionTime, username, vc, retries, totalTaskNumber, totalGpuNumber, state, completionTime.
CompletionTime maybe null for some jobs, these jobs will be returned at the end of the list when sorting by ASC order & at the beginning when sorting by DESC order.'
schema:
type: string
- name: withTotalCount
Expand Down
5 changes: 5 additions & 0 deletions src/rest-server/src/controllers/v2/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const list = asyncHandler(async (req, res) => {
'totalTaskNumber',
'totalGpuNumber',
'state',
'completionTime',
].includes(field)
) {
if (ordering === 'ASC' || ordering === 'DESC') {
Expand All @@ -101,6 +102,10 @@ const list = asyncHandler(async (req, res) => {
order.push(['userName', ordering]);
} else if (field === 'vc') {
order.push(['virtualCluster', ordering]);
} else if (field === 'completionTime') {
const orderingWithNulls =
ordering === 'ASC' ? 'ASC NULLS LAST' : 'DESC NULLS FIRST';
order.push(['completionTime', orderingWithNulls]);
} else {
order.push([field, ordering]);
}
Expand Down