@5minds/processcube_engine
Version:
The ProcessCube Engine. Stores and executes BPMNs.
152 lines • 8.14 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManualTaskInstanceHandler = void 0;
const inversify_1 = require("inversify");
const index_1 = require("../../../Contracts/InternalDataModels/index");
const index_2 = require("../../../Contracts/InternalMessages/index");
const AbortablePromise_1 = require("../../../Tools/AbortablePromise");
const EventAggregator_1 = __importDefault(require("../../../Tools/EventAggregator"));
const ActivityInstanceHandler_1 = require("./ActivityInstanceHandler");
let ManualTaskInstanceHandler = class ManualTaskInstanceHandler extends ActivityInstanceHandler_1.ActivityInstanceHandler {
finishManualTaskSubscription;
receivedFinishTaskEventId;
finishedByUserId;
loggerNamespace = 'manual_task';
get manualTask() {
return this.flowNode;
}
async afterExecute() {
await super.afterExecute();
EventAggregator_1.default.unsubscribe(this.finishManualTaskSubscription);
}
async persistOnExit(dataObjectValues) {
await super.persistOnExit(dataObjectValues, {
type: index_1.FlowNodeInstanceDataTypes.manualTask,
finishedByUserId: this.finishedByUserId,
});
if (this.receivedFinishTaskEventId) {
EventAggregator_1.default.acknowledgeEvent(this.receivedFinishTaskEventId);
}
this.publishManualTaskFinishedNotification();
}
async persistOnError(error) {
await super.persistOnError(error);
if (this.receivedFinishTaskEventId) {
EventAggregator_1.default.acknowledgeEvent(this.receivedFinishTaskEventId);
}
}
async persistOnTerminate() {
await super.persistOnTerminate();
if (this.receivedFinishTaskEventId) {
EventAggregator_1.default.acknowledgeEvent(this.receivedFinishTaskEventId);
}
}
async runHandler() {
this.logger.debug(`Executing ManualTask instance.`);
if (this.manualTask.requiresConfirmation === false) {
this.logger.debug('ManualTask does not require user input. Moving on to the next FlowNode.');
return;
}
const handlerPromise = new AbortablePromise_1.AbortablePromise(async (resolve, reject) => {
try {
const resultMessage = await this.suspendAndWaitForManualTaskResult();
this.currentToken = {};
this.logger.debug(`Resuming ManualTask instance.`);
this.finishedByUserId = resultMessage.finishedBy?.userId ?? this.processInstance.getOwner().userId;
return resolve();
}
catch (error) {
return reject(error);
}
}, { signal: this.activityHandler.abortSignal });
return handlerPromise;
}
async resumeAfterSuspend() {
const handlerPromise = new AbortablePromise_1.AbortablePromise(async (resolve, reject) => {
try {
const waitForMessagePromise = this.waitForManualTaskResult();
this.publishManualTaskReachedNotification();
const resultMessage = await waitForMessagePromise;
this.currentToken = {};
this.logger.debug(`Resuming ManualTask instance.`);
this.finishedByUserId = resultMessage.finishedBy?.userId ?? this.processInstance.getOwner().userId;
return resolve();
}
catch (error) {
return reject(error);
}
}, { signal: this.activityHandler.abortSignal });
return handlerPromise;
}
async suspendAndWaitForManualTaskResult() {
const waitForManualTaskResultPromise = this.waitForManualTaskResult();
await this.persistOnSuspend();
this.publishManualTaskReachedNotification();
return waitForManualTaskResultPromise;
}
waitForManualTaskResult() {
return new AbortablePromise_1.AbortablePromise(async (resolve) => {
const finishManualTaskEvent = index_2.eventAggregatorSettings.messagePaths.finishManualTask.replace(index_2.eventAggregatorSettings.messageParams.flowNodeInstanceId, this.flowNodeInstanceId);
this.finishManualTaskSubscription = EventAggregator_1.default.subscribeOnce(finishManualTaskEvent, (event) => {
this.receivedFinishTaskEventId = event.eventId;
resolve(event);
});
}, { signal: this.activityHandler.abortSignal });
}
publishManualTaskReachedNotification() {
const message = {
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
processInstanceId: this.processInstance.getProcessInstanceId(),
parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeInstanceId: this.flowNodeInstanceId,
processInstanceOwner: this.processInstance.getOwner(),
currentToken: this.currentToken,
previousFlowNodeInstanceId: this.previousFlowNodeInstanceId,
};
EventAggregator_1.default.publish(index_2.eventAggregatorSettings.messagePaths.manualTaskReached, message);
}
publishManualTaskFinishedNotification() {
const message = {
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
processInstanceId: this.processInstance.getProcessInstanceId(),
parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeInstanceId: this.flowNodeInstanceId,
processInstanceOwner: this.processInstance.getOwner(),
currentToken: this.currentToken,
previousFlowNodeInstanceId: this.previousFlowNodeInstanceId,
};
// FlowNode-specific notification
const manualTaskFinishedEvent = index_2.eventAggregatorSettings.messagePaths.manualTaskWithInstanceIdFinished.replace(index_2.eventAggregatorSettings.messageParams.flowNodeInstanceId, this.flowNodeInstanceId);
EventAggregator_1.default.publish(manualTaskFinishedEvent, message);
// Global notification
EventAggregator_1.default.publish(index_2.eventAggregatorSettings.messagePaths.manualTaskFinished, message);
}
};
exports.ManualTaskInstanceHandler = ManualTaskInstanceHandler;
exports.ManualTaskInstanceHandler = ManualTaskInstanceHandler = __decorate([
(0, inversify_1.injectable)()
], ManualTaskInstanceHandler);
//# sourceMappingURL=ManualTaskInstanceHandler.js.map