Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[teraslice] Add ex info option to teraslice v1 jobs api #3806

Merged
merged 3 commits into from
Oct 23, 2024
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
3 changes: 3 additions & 0 deletions docs/management-apis/endpoints-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ Returns an array of all jobs listed in `${clusterName}__jobs` index.
- `from: number = 0`
- `size: number = 100`
- `sort: string = "_updated:desc"`
- `ex: string = [execution controller field options]`

Setting `active` to `true` will return only the jobs considered active, which
includes the jobs that have `active` set to `true` as well as those that do not
Expand All @@ -264,6 +265,8 @@ Setting `deleted` to `true` will return all `_deleted: true` jobs.
The parameter `size` is the number of documents returned, `from` is how many
documents in and `sort` is a lucene query.

Refer to the returned object in [GET v1/ex](#get-v1ex) for valid `ex` parameter fields. This option is also used [here](#get-v1jobsjobid) and described in more detail.

**Usage:**

```sh
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "teraslice-workspace",
"displayName": "Teraslice",
"version": "2.6.1",
"version": "2.6.2",
"private": true,
"homepage": "https://github.com/terascope/teraslice",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/teraslice/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "teraslice",
"displayName": "Teraslice",
"version": "2.6.1",
"version": "2.6.2",
"description": "Distributed computing platform for processing JSON data",
"homepage": "https://github.com/terascope/teraslice#readme",
"bugs": {
Expand Down
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
Loading