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

fix(bpmn-service): fix worker execution issue in bpmn service #234

Merged
merged 1 commit into from
Jun 10, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class WorkflowController {
const workerList = workerMap[workflowName];
for (const worker of workerList) {
if (!worker.running) {
await this.workerFn(worker.topic, worker.command);
await this.workerFn(worker);
worker.running = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,25 @@ export class WorkerImplementationProvider
}
}
value(): WorkerImplementationFn {
return async (topic, cmd) => {
return async worker => {
if (this.client) {
this.client.subscribe(topic, ({task, taskService}) => {
cmd.operation({task, taskService}, (result: AnyObject) => {
if (result) {
this.ilogger.info(`Worker task completed - ${topic}`);
}
});
worker.running = true;
const subscription = this.client.subscribe(
worker.topic,
({task, taskService}) => {
worker.command.operation(
{task, taskService},
(result: AnyObject) => {
if (result) {
this.ilogger.info(`Worker task completed - ${worker.topic}`);
}
},
);
},
);
this.client.on('poll:error', () => {
worker.running = false;
subscription.unsubscribe();
});
} else {
throw new Error('Workflow client not connected');
Expand Down
2 changes: 1 addition & 1 deletion services/bpmn-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type WorkerNameCmdPair<T = AnyObject, R = AnyObject> = {
};

export interface WorkerImplementationFn<T = AnyObject, R = AnyObject> {
(topicName: string, commandCtor: BPMTask<T, R>): Promise<void>;
(worker: WorkerNameCmdPair<T, R>): Promise<void>;
}

export type SuccessResponse = {
Expand Down