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
7 changes: 3 additions & 4 deletions src/jobManagerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { httpClientConfig } from './models/utils';
export class JobManagerClient extends HttpClient {
public constructor(
protected readonly logger: Logger,
protected jobType: string,
protected jobManagerBaseUrl: string,
httpRetryConfig: IHttpRetryConfig | undefined = httpClientConfig,
targetService: string | undefined = 'jobManagerClient',
Expand Down Expand Up @@ -144,8 +143,8 @@ export class JobManagerClient extends HttpClient {
}
}

public async consume<T>(taskType: string): Promise<ITaskResponse<T> | null> {
const consumeTaskUrl = `/tasks/${this.jobType}/${taskType}/startPending`;
public async consume<T>(jobType: string, taskType: string): Promise<ITaskResponse<T> | null> {
const consumeTaskUrl = `/tasks/${jobType}/${taskType}/startPending`;
try {
const taskResponse = await this.post<ITaskResponse<T>>(consumeTaskUrl);
return taskResponse;
Expand All @@ -157,7 +156,7 @@ export class JobManagerClient extends HttpClient {
err,
url: consumeTaskUrl,
targetService: this.targetService,
jobType: this.jobType,
jobType,
taskType: taskType,
msg: `failed to consume task`,
errorMessage: (err as { message: string }).message,
Expand Down
19 changes: 9 additions & 10 deletions src/taskHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class TaskHandler {

public constructor(
protected readonly logger: Logger,
protected jobType: string,
protected jobManagerBaseUrl: string,
protected heartbeatUrl: string,
protected dequeueIntervalMs: number,
Expand All @@ -26,7 +25,7 @@ export class TaskHandler {
disableJobManagerDebugLogs: boolean | undefined = true,
disableHeartbeatDebugLogs: boolean | undefined = true
) {
this.jobManagerClient = new JobManagerClient(logger, jobType, jobManagerBaseUrl, httpRetryConfig, jobTargetService, disableJobManagerDebugLogs);
this.jobManagerClient = new JobManagerClient(logger, jobManagerBaseUrl, httpRetryConfig, jobTargetService, disableJobManagerDebugLogs);
this.heartbeatClient = new HeartbeatClient(
logger,
heartbeatIntervalMs,
Expand All @@ -37,23 +36,23 @@ export class TaskHandler {
);
}

public async waitForTask<T>(taskType: string): Promise<ITaskResponse<T>> {
public async waitForTask<T>(jobType: string, taskType: string): Promise<ITaskResponse<T>> {
let task: ITaskResponse<T> | null;
this.logger.info({
jobType: this.jobType,
jobType,
taskType,
msg: `waitForTask jobType=${this.jobType}, taskType=${taskType}`,
msg: `waitForTask jobType=${jobType}, taskType=${taskType}`,
});
do {
task = await this.dequeue(taskType);
task = await this.dequeue(jobType, taskType);
await new Promise((resolve) => setTimeout(resolve, this.dequeueIntervalMs));
} while (!task);
return task;
}

public async dequeue<T>(taskType: string): Promise<ITaskResponse<T> | null> {
public async dequeue<T>(jobType: string, taskType: string): Promise<ITaskResponse<T> | null> {
try {
const response = await this.jobManagerClient.consume<T>(taskType);
const response = await this.jobManagerClient.consume<T>(jobType, taskType);
if (response) {
const taskId = response.id;
this.heartbeatClient.start(taskId);
Expand All @@ -65,9 +64,9 @@ export class TaskHandler {
} else {
this.logger.error({
err,
jobType: this.jobType,
jobType,
taskType,
msg: `dequeue FAILED for jobType=${this.jobType}, taskType=${taskType}`,
msg: `dequeue FAILED for jobType=${jobType}, taskType=${taskType}`,
errorMessage: (err as { message: string }).message,
});
throw err;
Expand Down