Search code examples
javacamunda

Start camunda process in the suspended state


During data import task, I need to start multiple camunda process instances in some "paused" or suspended state. The process has some timers, and the values of that timers can be in the past. So if I start such a process normally, it will start execution of some tasks immediately, but I want to somehow postpone this execution (because the tasks are using some data, that is not yet imported). So, I want such behavior:

1) somehow pause the camunda engine, or the job executor, or the process definition.

2) import all required data, and at the same moment start all required processes

3) unpause the camunda, to let it run and execute previously started processes.

I've tried the following solutions:

1) globally suspend the process definition from the Cockpit. But when I start the process, it throws the exceptin, about supspended process definition. I start process with the following code:

runtimeService.createProcessInstanceByKey("process-key")
            .businessKey("some-business-key")
            .setVariables(vars)
            .startBeforeActivity("xxx")
            .execute();

2) start process with the same code, and in the same tx suspend the process instance runtimeService.suspendProcessInstanceById(processInstance.getProcessInstanceId()); But I get some exceptions, and incidents.

3) Disable camunda job executor globally, in the config file. Works fine, but not very convinient to modify config and restart server every time.

Are there any better solutions?


Solution

  • Found a way to control job executor in runtime.

        JobExecutor jobExecutor = ((ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration()).getJobExecutor();
        if (jobExecutor.isActive()) {
            jobExecutor.shutdown();
        } else {
            jobExecutor.start();
        }