Skip to content

Commit

Permalink
bump bpmn-moddle and chase that coverage flag
Browse files Browse the repository at this point in the history
  • Loading branch information
paed01 committed Jul 25, 2019
1 parent 9229060 commit 4f9d472
Show file tree
Hide file tree
Showing 23 changed files with 510 additions and 189 deletions.
10 changes: 1 addition & 9 deletions babel.config.js
@@ -1,15 +1,7 @@
/* global module, process, require */
/* global module */
module.exports = function babelRoot(api) {
api.cache(true);

if (process.env.NODE_ENV === 'test') {
require('@babel/register')({
// This will override `node_modules` ignoring - you can alternatively pass
// an array of strings to be explicitly matched or a regex / glob
ignore: ['node_modules/lodash'],
});
}

return {
presets: [
[
Expand Down
1 change: 0 additions & 1 deletion dist/src/definition/Definition.js
Expand Up @@ -382,7 +382,6 @@ function Definition(context, options) {
}

function publishEvent(action, content = {}) {
if (!action) return;
const msgOpts = {
type: action,
mandatory: action === 'error'
Expand Down
49 changes: 38 additions & 11 deletions dist/src/definition/DefinitionExecution.js
Expand Up @@ -100,18 +100,33 @@ function DefinitionExecution(definition) {
autoDelete: false
});
if (executeMessage.fields.redelivered) return resume(executeMessage);
activate();
start();
return true;
}

function resume() {
logger.debug(`<${executionId} (${id})> resume definition execution`);
logger.debug(`<${executionId} (${id})> resume`, status, 'definition execution');
if (completed) return complete('completed');
activate();
postponed.splice(0);
activityQ.consume(onChildEvent, {
prefetch: 1000
activityQ.consume(onProcessEvent, {
prefetch: 1000,
consumerTag: `_definition-activity-${executionId}`
});
if (completed) return complete('completed');

switch (status) {
case 'init':
return start();

case 'executing':
{
if (!postponed.length) return complete('completed');
break;
}
}

processes.forEach(p => p.resume());
}

Expand All @@ -120,13 +135,18 @@ function DefinitionExecution(definition) {
return publishCompletionMessage('completed');
}

if (!executableProcesses.length) return definition.emitFatal(new Error('No executable process'));
if (!executableProcesses.length) {
deactivate();
return definition.emitFatal(new Error('No executable process'));
}

status = 'start';
activate();
executableProcesses.forEach(prepareProcess);
executableProcesses.forEach(p => p.run());
activityQ.consume(onChildEvent, {
prefetch: 1000
postponed.splice(0);
activityQ.assertConsumer(onProcessEvent, {
prefetch: 1000,
consumerTag: `_definition-activity-${executionId}`
});
}

Expand All @@ -145,7 +165,6 @@ function DefinitionExecution(definition) {
}

function stop() {
status = 'stop';
return activityQ.queueMessage({
routingKey: 'execution.stop'
}, {
Expand All @@ -172,7 +191,8 @@ function DefinitionExecution(definition) {
executionId = state.executionId;
stopped = state.stopped;
completed = state.completed;
logger.debug(`<${executionId} (${id})> recover definition execution`);
status = state.status;
logger.debug(`<${executionId} (${id})> recover`, status, 'definition execution');
state.processes.forEach(processState => {
const instance = definition.getProcessById(processState.id);
if (!instance) return;
Expand All @@ -189,6 +209,7 @@ function DefinitionExecution(definition) {
}

function activate() {
console.log('activate');
processes.forEach(p => {
p.broker.subscribeTmp('message', 'message.outbound', onMessageOutbound, {
noAck: true,
Expand Down Expand Up @@ -236,14 +257,15 @@ function DefinitionExecution(definition) {

function deactivate() {
broker.cancel('_definition-api-consumer');
broker.cancel(`_definition-activity-${executionId}`);
processes.forEach(p => {
p.broker.cancel('_definition-message-consumer');
p.broker.cancel('_definition-activity-consumer');
p.broker.cancel('_definition-signal-consumer');
});
}

function complete(completionType, content = {}) {
function complete(completionType, content) {
deactivate();
logger.debug(`<${executionId} (${id})> definition execution ${completionType}`);
if (!content) content = createMessage();
Expand All @@ -260,7 +282,7 @@ function DefinitionExecution(definition) {
});
}

function onChildEvent(routingKey, message) {
function onProcessEvent(routingKey, message) {
const content = message.content;
const isRedelivered = message.fields.redelivered;
const {
Expand All @@ -281,6 +303,11 @@ function DefinitionExecution(definition) {
stateChangeMessage(true);

switch (routingKey) {
case 'process.discard':
case 'process.enter':
status = 'executing';
break;

case 'process.error':
{
processes.slice().forEach(p => {
Expand Down
6 changes: 3 additions & 3 deletions dist/src/error/Errors.js
Expand Up @@ -26,9 +26,9 @@ class ActivityError extends Error {

if (!inner) return;
this.inner = inner;
if ('name' in inner) this.name = inner.name;
if ('code' in inner) this.code = inner.code;
if ('id' in inner) this.id = inner.id;
if (inner.name) this.name = inner.name;
if (inner.code) this.code = inner.code;
if (inner.id) this.id = inner.id;
}

}
Expand Down
33 changes: 1 addition & 32 deletions dist/src/eventDefinitions/ErrorEventDefinition.js
Expand Up @@ -96,7 +96,7 @@ function ErrorEventDefinition(activity, eventDefinition) {
function catchError(routingKey, message, error) {
completed = true;
stop();
debug(`<${executionId} (${id})> caught ${description}`, (0, _messageHelper.shiftParent)(executeMessage.content.parent));
debug(`<${executionId} (${id})> caught ${description}`);
broker.publish('event', 'activity.catch', { ...messageContent,
source: {
id: message.content.id,
Expand Down Expand Up @@ -143,17 +143,12 @@ function ErrorEventDefinition(activity, eventDefinition) {
}

function executeThrow(executeMessage) {
let completed;
const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
const {
executionId,
parent
} = messageContent;
const parentExecutionId = parent && parent.executionId;
broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
noAck: true,
consumerTag: `_api-${executionId}`
});
const {
message: referenceMessage,
description
Expand All @@ -169,35 +164,9 @@ function ErrorEventDefinition(activity, eventDefinition) {
type: 'throw',
delegate: true
});
if (completed) return;
stop();
return broker.publish('execution', 'execute.completed', { ...messageContent,
message: referenceMessage
});

function onApiMessage(routingKey, message) {
const messageType = message.properties.type;

switch (messageType) {
case 'discard':
{
completed = true;
stop();
return broker.publish('execution', 'execute.discard', { ...messageContent
});
}

case 'stop':
{
stop();
break;
}
}
}

function stop() {
broker.cancel(`_api-${executionId}`);
}
}

function resolveMessage(message) {
Expand Down
8 changes: 7 additions & 1 deletion dist/src/flows/SequenceFlow.js
Expand Up @@ -214,7 +214,13 @@ function SequenceFlow(flowDef, {
return onEvaluateError && onEvaluateError(err);
}

return script.execute((0, _ExecutionScope.default)(flowApi, message));
try {
return script.execute((0, _ExecutionScope.default)(flowApi, message));
} catch (err) {
if (!onEvaluateError) throw err;
logger.error(`<${id}>`, err);
onEvaluateError(err);
}
}
};
}
Expand Down
12 changes: 6 additions & 6 deletions dist/src/gateways/ExclusiveGateway.js
Expand Up @@ -36,11 +36,10 @@ function ExclusiveGatewayBehaviour(activity) {
function execute(executeMessage) {
const content = (0, _messageHelper.cloneContent)(executeMessage.content);
if (!outboundSequenceFlows.length) return complete();
let conditionMet, defaultFlow, stop;
let conditionMet, defaultFlow, evaluateError;
const outbound = content.outbound = [];

for (let i = 0; i < outboundSequenceFlows.length; i++) {
if (stop) return;
const flow = outboundSequenceFlows[i];

if (conditionMet) {
Expand All @@ -63,15 +62,16 @@ function ExclusiveGatewayBehaviour(activity) {
action: 'take'
});
} else {
if (evaluateError) return broker.publish('execution', 'execute.error', { ...content,
error: evaluateError
});
outbound.push({
id: flow.id,
action: 'discard'
});
}
}

if (stop) return;

if (defaultFlow) {
if (conditionMet) {
outbound.push({
Expand Down Expand Up @@ -99,8 +99,8 @@ function ExclusiveGatewayBehaviour(activity) {
broker.publish('execution', 'execute.completed', content);
}

function onEvaluateError() {
stop = true;
function onEvaluateError(err) {
evaluateError = err;
}
}
}
12 changes: 6 additions & 6 deletions dist/src/gateways/InclusiveGateway.js
Expand Up @@ -36,11 +36,10 @@ function InclusiveGatewayBehaviour(activity) {
function execute(executeMessage) {
const content = (0, _messageHelper.cloneContent)(executeMessage.content);
if (!outboundSequenceFlows.length) return complete();
let conditionMet, defaultFlow, stop;
let conditionMet, defaultFlow, evaluateError;
const outbound = content.outbound = [];

for (let i = 0; i < outboundSequenceFlows.length; i++) {
if (stop) return;
const flow = outboundSequenceFlows[i];

if (flow.isDefault) {
Expand All @@ -55,15 +54,16 @@ function InclusiveGatewayBehaviour(activity) {
action: 'take'
});
} else {
if (evaluateError) return broker.publish('execution', 'execute.error', { ...content,
error: evaluateError
});
outbound.push({
id: flow.id,
action: 'discard'
});
}
}

if (stop) return;

if (defaultFlow) {
if (conditionMet) {
outbound.push({
Expand Down Expand Up @@ -91,8 +91,8 @@ function InclusiveGatewayBehaviour(activity) {
broker.publish('execution', 'execute.completed', content);
}

function onEvaluateError() {
stop = true;
function onEvaluateError(err) {
evaluateError = err;
}
}
}
54 changes: 27 additions & 27 deletions dist/src/process/ProcessExecution.js
Expand Up @@ -112,33 +112,6 @@ function ProcessExecution(parentActivity, context) {
return true;
}

function recover(state) {
if (!state) return processExecution;
executionId = state.executionId;
stopped = state.stopped;
completed = state.completed;
status = state.status;
logger.debug(`<${executionId} (${id})> recover`, status, 'process execution');

if (state.flows) {
state.flows.forEach(flowState => {
const flow = getFlowById(flowState.id);
if (!flow) return;
flow.recover(flowState);
});
}

if (state.children) {
state.children.forEach(childState => {
const child = getActivityById(childState.id);
if (!child) return;
child.recover(childState);
});
}

return processExecution;
}

function resume() {
logger.debug(`<${executionId} (${id})> resume`, status, 'process execution');
if (completed) return complete('completed');
Expand Down Expand Up @@ -186,6 +159,33 @@ function ProcessExecution(parentActivity, context) {
});
}

function recover(state) {
if (!state) return processExecution;
executionId = state.executionId;
stopped = state.stopped;
completed = state.completed;
status = state.status;
logger.debug(`<${executionId} (${id})> recover`, status, 'process execution');

if (state.flows) {
state.flows.forEach(flowState => {
const flow = getFlowById(flowState.id);
if (!flow) return;
flow.recover(flowState);
});
}

if (state.children) {
state.children.forEach(childState => {
const child = getActivityById(childState.id);
if (!child) return;
child.recover(childState);
});
}

return processExecution;
}

function stop() {
getApi().stop();
}
Expand Down

0 comments on commit 4f9d472

Please sign in to comment.