简体   繁体   中英

Camunda - executing processes in specific order

Let's say that we have bussiness process A . Process A might take more or less time (it's not known).

Normally you can have multiple A processes, but sometimes during some operations we need to make sure that one process execution is made after previous one.

How can we achieve it in Camunda? Tried to find something like process dependency (so process starts after previous one is complete), but couldn't find anything :(

I thought about adding some variable in process (like depending_process ) and checking if specified process is done, but maybe there would be some better solution.

Ok, after some research I got solution.

On the beginning of every process I check for processes started by current user:

final DateTime selfOrderDate = (DateTime) execution.getVariable(PROCESS_ORDER_DATE);

List<ProcessInstance> processInstanceList = execution
        .getProcessEngineServices()
        .getRuntimeService()
        .createProcessInstanceQuery()
        .processDefinitionId(execution.getProcessDefinitionId())
        .variableValueEquals(CUSTOMER_ID, execution.getVariable(CUSTOMER_ID))
        .active()
        .list();

int processesOrderedBeforeCurrentCount = 0;
for (ProcessInstance processInstance : processInstanceList) {
    ExecutionEntity entity = (ExecutionEntity) processInstance;

    if (processInstance.getId().equals(execution.getId()))
        continue;

    DateTime orderDate = (DateTime) entity.getVariable(PROCESS_ORDER_DATE);
    if (selfOrderDate.isAfter(orderDate)) {
        processesOrderedBeforeCurrentCount += 1;
    }
}

Then I save number of previously started processes to Camunda and in next task check if it's equal to 0. If yes, I proceed, if nope, I wait 1s (using Camunda's timer) and check again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM