Skip to content

Commit 2e0bbb9

Browse files
authored
feat: support jobs/find route in jobManager (MAPCO-4427 , MAPCO-4431) (#38)
* feat: support jobs/find route in jobManager * fix: rename to plural
1 parent 4366699 commit 2e0bbb9

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/jobManagerClient.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
IUpdateJobBody,
1212
IUpdateTaskBody,
1313
IFindJobsRequest,
14+
IFindJobsByCriteriaBody,
1415
} from './models/dataTypes';
1516
import { httpClientConfig } from './models/utils';
1617

@@ -143,6 +144,50 @@ export class JobManagerClient extends HttpClient {
143144
}
144145
}
145146

147+
public async findJobs<T, P>(findJobsParams: IFindJobsByCriteriaBody): Promise<IJobResponse<T, P>[]> {
148+
const findJobsUrl = this.findJobsUrl();
149+
if (findJobsParams.resourceId !== undefined) {
150+
findJobsParams.resourceId = encodeURIComponent(findJobsParams.resourceId);
151+
}
152+
if (findJobsParams.productType !== undefined) {
153+
findJobsParams.productType = encodeURIComponent(findJobsParams.productType);
154+
}
155+
try {
156+
this.logger.debug({
157+
url: findJobsUrl,
158+
targetService: this.targetService,
159+
findJobsParams,
160+
msg: `findJobs`,
161+
});
162+
const res = await this.post<IJobResponse<T, P>[]>(findJobsUrl, {
163+
resourceId: findJobsParams.resourceId,
164+
version: findJobsParams.version,
165+
isCleaned: findJobsParams.isCleaned,
166+
productType: findJobsParams.productType,
167+
statuses: findJobsParams.statuses,
168+
types: findJobsParams.types,
169+
shouldReturnTasks: findJobsParams.shouldReturnTasks,
170+
fromDate: findJobsParams.fromDate,
171+
tillDate: findJobsParams.tillDate,
172+
internalId: findJobsParams.internalId,
173+
});
174+
if (typeof res === 'string' || res.length === 0) {
175+
return [];
176+
}
177+
return res;
178+
} catch (err) {
179+
this.logger.error({
180+
err,
181+
url: findJobsUrl,
182+
targetService: this.targetService,
183+
findJobsParams,
184+
msg: `failed to findJobs`,
185+
errorMessage: (err as { message: string }).message,
186+
});
187+
throw err;
188+
}
189+
}
190+
146191
public async consume<T>(jobType: string, taskType: string): Promise<ITaskResponse<T> | null> {
147192
const consumeTaskUrl = `/tasks/${jobType}/${taskType}/startPending`;
148193
try {
@@ -371,6 +416,11 @@ export class JobManagerClient extends HttpClient {
371416
return jobsUrl;
372417
}
373418

419+
protected findJobsUrl(): string {
420+
const jobsUrl = '/jobs/find';
421+
return jobsUrl;
422+
}
423+
374424
protected getJobUrl(jobId: string): string {
375425
const jobUrl = `/jobs/${jobId}`;
376426
return jobUrl;

src/models/dataTypes.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,19 @@ export interface IFindJobsRequest {
125125
internalId?: string;
126126
}
127127

128+
export interface IFindJobsByCriteriaBody {
129+
resourceId?: string;
130+
version?: string;
131+
isCleaned?: boolean;
132+
statuses?: OperationStatus[];
133+
types?: string[];
134+
shouldReturnTasks?: boolean;
135+
shouldReturnAvailableActions?: boolean;
136+
productType?: string;
137+
fromDate?: string;
138+
tillDate?: string;
139+
internalId?: string;
140+
domain?: string;
141+
}
142+
128143
export interface IFindTaskRequest<T> extends Partial<ITaskResponse<T>> {}

0 commit comments

Comments
 (0)