Getting error while cleanup historical data

below is the the implemeation :slight_smile:

public void execute(DelegateExecution delegateExecution) throws Exception {
      System.out.println("--->"+ "deleting...");
    try {
        deleteUnusedDeployments(delegateExecution);
    } catch (RuntimeException e) {
        throw new BpmnError("cleanupException", "Message: " + e.getMessage() + ", Stacktrace: " + e.getStackTrace());
    }
}

private void deleteUnusedDeployments(DelegateExecution delegateExecution) {
    System.out.println("--->"+repositoryService.createDeploymentQuery().list());
    List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
    System.out.println("--->"+ deployments.get(0));

    for (Deployment deployment : deployments) {
        boolean deploymentCanBeDeleted = true;

        List<ProcessDefinition> processDefinitions = repositoryService
                .createProcessDefinitionQuery()
                .deploymentId(deployment.getId()).list();
        System.out.println("--->"+  repositoryService
                .createProcessDefinitionQuery()
                .deploymentId(deployment.getId()).list());
        for (ProcessDefinition processDefinition : processDefinitions) {
            ProcessDefinition latestProcessDefiniton = repositoryService
                    .createProcessDefinitionQuery()
                    .processDefinitionKey(processDefinition.getKey())
                    .latestVersion().singleResult();
            boolean isLatest = latestProcessDefiniton.getId().equals(processDefinition.getId());
            boolean hasRunningInstances = runtimeService
                    .createProcessInstanceQuery()
                    .processDefinitionId(processDefinition.getId()).count() > 0;
            boolean hasHistoricInstances = historyService
                    .createHistoricProcessInstanceQuery()
                    .processDefinitionId(processDefinition.getId()).count() > 0;
            if (isLatest || hasRunningInstances || hasHistoricInstances) {
                deploymentCanBeDeleted = false;
                break;
            }
        }
        if (deploymentCanBeDeleted) {
            //repositoryService.deleteDeployment(deployment.getId());
            System.out.println("deleted tem successfully");
        }

    }
}

}

Camunda:


Below Error getting:
—>deleting…
2021-10-11 21:48:20.714 INFO 29836 — [aTaskExecutor-1] org.camunda.bpm.engine.bpmn.behavior : ENGINE-02001 Execution with id ‘say-hello’ throws an error event with errorCode ‘cleanupException’, but no catching boundary event was defined. Execution is ended (none end event semantics).

Hi @Shashi_Bhushan,

I can’t see the root-cause, but be careful with BpmnErrors, see BpmnError.java:

/**
 * Special exception that can be used to throw a BPMN Error from
 * {@link JavaDelegate}s and expressions.
 * 
 * This should only be used for business faults, which shall be handled by a
 * Boundary Error Event or Error Event Sub-Process modeled in the process
 * definition. Technical errors should be represented by other exception types.
 */

So, if you don’t have any catching boundary event defined as part of your process-model, all process-instances will end without any remaining part in case of error.

BR rnschk :slight_smile:

2 Likes

Thanks @rnschk ! got resolved…

1 Like