【问题标题】:How to query scheduled processes (timer events)?如何查询计划进程(定时器事件)?
【发布时间】:2014-04-08 09:19:58
【问题描述】:

如果我使用计时器启动事件来安排进程的启动时间,我如何查询哪些进程将启动以及何时启动?

另外,对于捕获计时器中间事件,我也有同样的问题。 camunda 引擎是否提供 API(Java 或 REST)来查询哪些计时器正在运行以及它们预计何时到期?

【问题讨论】:

    标签: java rest business-process-management camunda


    【解决方案1】:

    您可以通过 Java 和 REST API 检索使用计时器事件的进程的下一个计划执行时间,如下所示:

    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;
      }
    }
    

    示例 REST API:

    使用http://localhost:8080/engine-rest/process-definition/ 检索流程定义

    对于每个流程定义,通过以下方式查询作业定义 http://localhost:8080/engine-rest/job-definition?active=true&processDefinitionId=${YOUR_PROCESS_DEFINITION_ID}

    对于每个流程定义,通过http://localhost:8080/engine-rest/job?active=true&amp;timers=true&amp;processDefinitionId=${YOUR_PROCESS_DEFINITION_ID}查询作业

    那么您必须使用 jobConfigurationId 将生成的作业与作业配置相关联。

    【讨论】:

      猜你喜欢
      • 2020-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多