You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

92 lines
2.7 KiB

const path = require('path');
const { sleep } = require('./util');
const { getAllWorkflows } = require('./workflow');
const { getAllProcesses, getProcessPaths } = require('./process');
require(path.join(process.cwd(), "..", "server", "dist", "database.js"));
(async function () {
await sleep(5e3);
console.time("WorkflowTester")
console.log("initilizing begin..");
const workflows = await getAllWorkflows({
id: {
[Op.gt]: 0
}
});
if (workflows.length == 0) throw "There is not any workflow";
const allWorkFlowInfo = {};
workflowsFor:
for await (const workflow of workflows) {
if (+workflow.id < 0) continue;
const processes = await getAllProcesses(workflow, {
subFlowId: null,
});
if (processes.length == 0) {
allWorkFlowInfo[workflow.id] = {
isValid: false,
root: {
valid: 0,
invalid: 0,
subFlowList: []
},
subFlow: {}
}
continue workflowsFor;
}
const { allPaths: tree, subFlowParentIds, invalidPathsWithoutEnding } = await getProcessPaths(processes, workflow);
allWorkFlowInfo[workflow.id] = {
isValid: invalidPathsWithoutEnding.length == 0 ? true : false,
root: {
validPaths: tree,
invalidPaths: invalidPathsWithoutEnding,
valid: tree.length,
invalid: invalidPathsWithoutEnding.length,
subFlowList: subFlowParentIds
},
subFlow: {}
}
const subFlowInfo = {}
subFlowFor:
for await (const subFlowId of subFlowParentIds) {
const processesSubFlow = await getAllProcesses(workflow, {
[Op.or]: [
{
subFlowId: subFlowId,
},
{
subFlowPid: subFlowId
}
]
})
if (processesSubFlow.length == 0) {
allWorkFlowInfo[workflow.id].isValid = false;
subFlowInfo[subFlowId] = {
valid: subTreePath.length,
invalid: invalidSubPathsWithoutEnding.length,
validSubTreePath:subTreePath,
invalidSubTreePath: invalidSubPathsWithoutEnding
}
continue subFlowFor;
}
}
allWorkFlowInfo[workflow.id]["subFlow"] = subFlowInfo;
console.log("allWorkFlowInfo",JSON.stringify(allWorkFlowInfo,null,2));
}
console.timeEnd("WorkflowTester")
console.log("DONE");
})()