Refactoring of handleUpdateProcess to try to commit again processes that have not been commited
This commit is contained in:
parent
f0151fa55e
commit
cb5297e6fe
@ -597,9 +597,28 @@ export async function registerAllListeners() {
|
|||||||
if (!process) {
|
if (!process) {
|
||||||
throw new Error('Process not found');
|
throw new Error('Process not found');
|
||||||
}
|
}
|
||||||
const lastState = services.getLastCommitedState(process);
|
let lastState = services.getLastCommitedState(process);
|
||||||
if (!lastState) {
|
if (!lastState) {
|
||||||
throw new Error('Process doesn\'t have a commited state yet');
|
const firstState = process.states[0];
|
||||||
|
const roles = firstState.roles;
|
||||||
|
if (services.rolesContainsUs(roles)) {
|
||||||
|
const approveChangeRes= await services.approveChange(processId, firstState.state_id);
|
||||||
|
await services.handleApiReturn(approveChangeRes);
|
||||||
|
const prdUpdateRes = await services.createPrdUpdate(processId, firstState.state_id);
|
||||||
|
await services.handleApiReturn(prdUpdateRes);
|
||||||
|
} else {
|
||||||
|
if (firstState.validation_tokens.length > 0) {
|
||||||
|
// Try to send it again anyway
|
||||||
|
const res = await services.createPrdUpdate(processId, firstState.state_id);
|
||||||
|
await services.handleApiReturn(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Wait a couple seconds
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
|
lastState = services.getLastCommitedState(process);
|
||||||
|
if (!lastState) {
|
||||||
|
throw new Error('Process doesn\'t have a commited state yet');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const lastStateIndex = services.getLastCommitedStateIndex(process);
|
const lastStateIndex = services.getLastCommitedStateIndex(process);
|
||||||
if (lastStateIndex === null) {
|
if (lastStateIndex === null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user