Automatically start process execution in loadProcess function within [id].vue, enhancing workflow initiation. Improved error handling with user-friendly messages for various failure scenarios.
This commit is contained in:
parent
3f0c13cafd
commit
cddf0d7836
@ -199,8 +199,12 @@ const loadProcess = async (retryCount = 0) => {
|
|||||||
// Reset visited nodes tracking for new process execution
|
// Reset visited nodes tracking for new process execution
|
||||||
visitedNodesInSession.value.clear();
|
visitedNodesInSession.value.clear();
|
||||||
|
|
||||||
// Start the process execution (case instance)
|
// Automatically start the process execution (case instance)
|
||||||
// await startProcessExecution();
|
// This will create the case and move to the first actual task
|
||||||
|
await startProcessExecution();
|
||||||
|
|
||||||
|
// Loading will be set to false after the first step is ready
|
||||||
|
loading.value = false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(response.message || 'Invalid process response');
|
throw new Error(response.message || 'Invalid process response');
|
||||||
@ -224,36 +228,65 @@ const loadProcess = async (retryCount = 0) => {
|
|||||||
notifyParentOfError(error.value);
|
notifyParentOfError(error.value);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
} finally {
|
} finally {
|
||||||
// Only set loading to false if we're not retrying
|
// Loading state is now managed after startProcessExecution completes
|
||||||
if (retryCount >= 2 || process.value) {
|
// Only set loading to false here if there was an error
|
||||||
|
if (!process.value && retryCount >= 2) {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start process execution (create case instance)
|
// Start process execution (create case instance and begin workflow)
|
||||||
const startProcessExecution = async () => {
|
const startProcessExecution = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('[Workflow] Starting process execution (creating case instance)...');
|
console.log('[Workflow] Starting process execution automatically...');
|
||||||
|
|
||||||
|
// Create case instance via API
|
||||||
const response = await $fetch(`/api/process/${processId.value}/start`, {
|
const response = await $fetch(`/api/process/${processId.value}/start`, {
|
||||||
method: 'POST'
|
method: 'POST',
|
||||||
|
body: {
|
||||||
|
variables: processVariables.value // Pass initial variables if any
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
caseInstance.value = response.data.case;
|
caseInstance.value = response.data.case;
|
||||||
tasks.value = response.data.tasks;
|
tasks.value = response.data.tasks || [];
|
||||||
console.log('[Workflow] Case instance created:', caseInstance.value);
|
console.log('[Workflow] Case instance created:', caseInstance.value);
|
||||||
// Find the start node
|
|
||||||
|
// Find the start node and move past it to the first actual step
|
||||||
const startNodeIndex = workflowData.value.nodes.findIndex(node => node.type === 'start');
|
const startNodeIndex = workflowData.value.nodes.findIndex(node => node.type === 'start');
|
||||||
currentStep.value = startNodeIndex >= 0 ? startNodeIndex : 0;
|
if (startNodeIndex >= 0) {
|
||||||
console.log('[Workflow] Starting at node index:', currentStep.value, workflowData.value.nodes[currentStep.value]);
|
currentStep.value = startNodeIndex;
|
||||||
moveToNextStep();
|
console.log('[Workflow] Found start node at index:', startNodeIndex);
|
||||||
|
|
||||||
|
// Immediately move to the first actual task after the start node
|
||||||
|
moveToNextStep();
|
||||||
|
} else {
|
||||||
|
// No start node found, begin at first node
|
||||||
|
console.warn('[Workflow] No start node found, beginning at first node');
|
||||||
|
currentStep.value = 0;
|
||||||
|
|
||||||
|
// If the first node is executable, run it
|
||||||
|
if (currentNode.value && ['api', 'script', 'notification'].includes(currentNode.value.type)) {
|
||||||
|
await executeCurrentStep();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(response.error || 'Failed to start process');
|
throw new Error(response.error || 'Failed to start process');
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[Workflow] Error starting process execution:', err);
|
console.error('[Workflow] Error starting process execution:', err);
|
||||||
error.value = 'Failed to start process execution';
|
|
||||||
|
// More user-friendly error message
|
||||||
|
if (err.statusCode === 404) {
|
||||||
|
error.value = 'Process not found. Please check if the process exists and is published.';
|
||||||
|
} else if (err.statusCode === 403) {
|
||||||
|
error.value = 'You do not have permission to execute this process.';
|
||||||
|
} else {
|
||||||
|
error.value = `Failed to start process: ${err.message || 'Unknown error'}`;
|
||||||
|
}
|
||||||
|
|
||||||
notifyParentOfError(error.value);
|
notifyParentOfError(error.value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user