AnsweredAssumed Answered

Detect ended process instance

Question asked by dibrandt on Feb 27, 2014
Latest reply on Mar 1, 2014 by trademak
Hello,

we use this method to detect a ended process instance.
We call the method after the engine fired an event at the end event node.
Is this the best method to detect a ended instance? Is the List<Execution> always empty?  Or exists a other solution?


    public void detectProcStatusFromActivity() {
        if(this.status == null) {
            if (this.processInstanceId == null) {
                LOG.debug("Could not detect processState without processInstanceId");
            } else {
   
                try {
                    List<Execution> executions = getActivitiRuntimeService().createExecutionQuery()
                            .processInstanceId(this.processInstanceId).list();
                    if (executions.isEmpty()) {
                        this.status = ProcStatus.CLOSED;
                    }
                } catch (ActivitiException e) {
                    LOG.debug(
                            "Exception while trying to find Activiti process instance for instanceId {}, " +
                            "assuming new process state: CLOSED.",  processInstanceId, e);
                    this.status = ProcStatus.CLOSED;
                }
            }
        }
    }

Outcomes