🐛 Fix that static data did not always get load on execution

This commit is contained in:
Jan Oberhauser 2019-10-15 07:36:53 +02:00
parent 369e8084d3
commit 542ae1e785
5 changed files with 32 additions and 5 deletions

View file

@ -263,7 +263,7 @@ export class ActiveWorkflowRunner {
};
const workflowRunner = new WorkflowRunner();
workflowRunner.run(runData);
workflowRunner.run(runData, true);
};
return returnFunctions;
});

View file

@ -224,7 +224,7 @@ export function getWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflo
// Start now to run the workflow
const workflowRunner = new WorkflowRunner();
const executionId = await workflowRunner.run(runData);
const executionId = await workflowRunner.run(runData, true);
// Get a promise which resolves when the workflow did execute and send then response
const executePromise = activeExecutions.getPostExecutePromise(executionId) as Promise<IExecutionDb | undefined>;

View file

@ -158,7 +158,7 @@ const hooks = (mode: WorkflowExecuteMode, workflowData: IWorkflowBase, execution
workflowExecuteAfter: [
async (fullRunData: IRun, newStaticData: IDataObject): Promise<void> => {
try {
if (WorkflowHelpers.isWorkflowIdValid(workflowData.id as string) === true) {
if (mode !== 'manual' && WorkflowHelpers.isWorkflowIdValid(workflowData.id as string) === true) {
// Workflow is saved so update in database
try {
await WorkflowHelpers.saveStaticDataById(workflowData.id as string, newStaticData);

View file

@ -62,7 +62,7 @@ export async function executeErrorWorkflow(workflowId: string, workflowErrorData
const executionMode = 'error';
const nodeTypes = NodeTypes();
const workflowInstance = new Workflow(workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, undefined, workflowData.settings);
const workflowInstance = new Workflow(workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings);
let node: INode;
@ -168,3 +168,23 @@ export async function saveStaticDataById(workflowId: string | number, newStaticD
staticData: newStaticData,
});
}
/**
* Returns the static data of workflow
*
* @export
* @param {(string | number)} workflowId The id of the workflow to get static data of
* @returns
*/
export async function getStaticDataById(workflowId: string | number) {
const workflowData = await Db.collections.Workflow!
.findOne(workflowId, { select: ['staticData']});
if (workflowData === undefined) {
return {};
}
return workflowData.staticData || {};
}

View file

@ -8,6 +8,7 @@ import {
NodeTypes,
Push,
WorkflowExecuteAdditionalData,
WorkflowHelpers,
} from './';
import {
@ -140,13 +141,19 @@ export class WorkflowRunner {
* Run the workflow in subprocess
*
* @param {IWorkflowExecutionDataProcess} data
* @param {boolean} [loadStaticData] If set will the static data be loaded from
* the workflow and added to input data
* @returns {Promise<string>}
* @memberof WorkflowRunner
*/
async run(data: IWorkflowExecutionDataProcess): Promise<string> {
async run(data: IWorkflowExecutionDataProcess, loadStaticData?: boolean): Promise<string> {
const startedAt = new Date();
const subprocess = fork(pathJoin(__dirname, 'WorkflowRunnerProcess.js'));
if (loadStaticData === true && data.workflowData.id) {
data.workflowData.staticData = await WorkflowHelpers.getStaticDataById(data.workflowData.id as string);
}
// Register the active execution
const executionId = this.activeExecutions.add(subprocess, data);