You can retrieve the next scheduled execution times of your processes which use timer events through the Java and REST API like the following:
Example Java API:
import org.camunda.bpm.ProcessEngineService;
import org.camunda.bpm.container.RuntimeContainerDelegate;
import org.camunda.bpm.engine.ManagementService;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.management.JobDefinition;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.Job;
import java.util.HashMap;
import java.util.List;
public class StackOverflow {
public HashMap<ProcessDefinition, List<Job>> queryNextScheduledExecutionOfTimers() {
ProcessEngineService processEngineService =
RuntimeContainerDelegate.INSTANCE.get().getProcessEngineService();
ProcessEngine defaultProcessEngine = processEngineService.getDefaultProcessEngine();
// optional step - get all active process definitions
RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
List<ProcessDefinition> processDefinitions =
repositoryService.createProcessDefinitionQuery().active().list();
ManagementService managementService = defaultProcessEngine.getManagementService();
HashMap<ProcessDefinition,List<Job>> timerJobsByProcessDefinition = new HashMap<ProcessDefinition, List<Job>>();
for (ProcessDefinition processDefinition : processDefinitions) {
List<JobDefinition> jobDefinitions =
managementService.createJobDefinitionQuery()
.active()
.processDefinitionId(processDefinition.getId())
.list();
for (JobDefinition jobDefinition : jobDefinitions) {
// if you want to lookup the activity to highlight it inside the process diagram for example
String activityId = jobDefinition.getActivityId();
// if you want to display the configured expression / date / cron expression when the timer should fire
String jobConfiguration = jobDefinition.getJobConfiguration();
// if you want to distinguish between timer start event / catching timer intermediate event / boundary timer event
String timerType = jobDefinition.getJobType();
List<Job> jobs = managementService.createJobQuery()
.active()
.timers()
.jobDefinitionId(jobDefinition.getId())
.orderByJobDuedate()
.list();
timerJobsByProcessDefinition.put(processDefinition, jobs);
}
}
return timerJobsByProcessDefinition;
}
}
Example REST API:
use http://localhost:8080/engine-rest/process-definition/
to retrieve the process definitions
for each process definition query the job definitions via
http://localhost:8080/engine-rest/job-definition?active=true&processDefinitionId=${YOUR_PROCESS_DEFINITION_ID}
for each process definition query the jobs via http://localhost:8080/engine-rest/job?active=true&timers=true&processDefinitionId=${YOUR_PROCESS_DEFINITION_ID}
then you must correlate the resulting jobs with the job configurations using the jobConfigurationId.