Skip to content
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
50 changes: 50 additions & 0 deletions src/jobManagerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
IUpdateJobBody,
IUpdateTaskBody,
IFindJobsRequest,
IFindJobsByCriteriaBody,
} from './models/dataTypes';
import { httpClientConfig } from './models/utils';

Expand Down Expand Up @@ -143,6 +144,50 @@ export class JobManagerClient extends HttpClient {
}
}

public async findJobs<T, P>(findJobsParams: IFindJobsByCriteriaBody): Promise<IJobResponse<T, P>[]> {
const findJobsUrl = this.findJobsUrl();
if (findJobsParams.resourceId !== undefined) {
findJobsParams.resourceId = encodeURIComponent(findJobsParams.resourceId);
}
if (findJobsParams.productType !== undefined) {
findJobsParams.productType = encodeURIComponent(findJobsParams.productType);
}
try {
this.logger.debug({
url: findJobsUrl,
targetService: this.targetService,
findJobsParams,
msg: `findJobs`,
});
const res = await this.post<IJobResponse<T, P>[]>(findJobsUrl, {
resourceId: findJobsParams.resourceId,
version: findJobsParams.version,
isCleaned: findJobsParams.isCleaned,
productType: findJobsParams.productType,
statuses: findJobsParams.statuses,
types: findJobsParams.types,
shouldReturnTasks: findJobsParams.shouldReturnTasks,
fromDate: findJobsParams.fromDate,
tillDate: findJobsParams.tillDate,
internalId: findJobsParams.internalId,
});
if (typeof res === 'string' || res.length === 0) {
return [];
}
return res;
} catch (err) {
this.logger.error({
err,
url: findJobsUrl,
targetService: this.targetService,
findJobsParams,
msg: `failed to findJobs`,
errorMessage: (err as { message: string }).message,
});
throw err;
}
}

public async consume<T>(jobType: string, taskType: string): Promise<ITaskResponse<T> | null> {
const consumeTaskUrl = `/tasks/${jobType}/${taskType}/startPending`;
try {
Expand Down Expand Up @@ -371,6 +416,11 @@ export class JobManagerClient extends HttpClient {
return jobsUrl;
}

protected findJobsUrl(): string {
const jobsUrl = '/jobs/find';
return jobsUrl;
}

protected getJobUrl(jobId: string): string {
const jobUrl = `/jobs/${jobId}`;
return jobUrl;
Expand Down
15 changes: 15 additions & 0 deletions src/models/dataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,19 @@ export interface IFindJobsRequest {
internalId?: string;
}

export interface IFindJobsByCriteriaBody {
resourceId?: string;
version?: string;
isCleaned?: boolean;
statuses?: OperationStatus[];
types?: string[];
shouldReturnTasks?: boolean;
shouldReturnAvailableActions?: boolean;
productType?: string;
fromDate?: string;
tillDate?: string;
internalId?: string;
domain?: string;
}

export interface IFindTaskRequest<T> extends Partial<ITaskResponse<T>> {}