Skip to content

Commit

Permalink
add ex query to api/v1jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
sotojn committed Oct 23, 2024
1 parent 05d48a2 commit 80e2721
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/teraslice/src/lib/cluster/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class ApiService {
});

v1routes.get('/jobs', (req, res) => {
const { active = '', deleted = 'false' } = req.query;
const { active = '', deleted = 'false', ex } = req.query;
const { size, from, sort } = getSearchOptions(req as TerasliceRequest);

const requestHandler = handleTerasliceRequest(req as TerasliceRequest, res, 'Could not retrieve list of jobs');
Expand All @@ -280,8 +280,9 @@ export class ApiService {

const partialQuery = createJobActiveQuery(active as string);
const query = addDeletedToQuery(deleted as string, partialQuery);

return this.jobsStorage.search(query, from, size, sort as string);
return typeof ex === 'string'
? this.jobsService.getJobsWithExInfo(query, from, size, sort as string, ex.split(','))
: this.jobsStorage.search(query, from, size, sort as string);
});
});

Expand Down
25 changes: 25 additions & 0 deletions packages/teraslice/src/lib/cluster/services/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,31 @@ export class JobsService {
return job;
}

/**
* Get a list of jobs with the latest ex status for each one
*
* @param {string} query
* @param {number} from
* @param {number} size
* @param {string} sort
* @param {string} [ex_fields]
* @returns {Promise<JobConfig>}
*/
async getJobsWithExInfo(
query: string | Record<string, any>,
from?: number,
size?: number,
sort?: string,
ex_fields?: string[]
): Promise<JobConfig[]> {
const jobList = await this.jobsStorage.search(query, from, size, sort);
const finalList: JobConfig[] = [];
for (const job of jobList) {
finalList.push(await this.getJobWithExInfo(job.job_id, ex_fields));
}
return finalList;
}

/**
* Get the active execution
*
Expand Down

0 comments on commit 80e2721

Please sign in to comment.