Search in sources :

Example 1 with ExecuteJobsCmd

use of org.activiti.engine.impl.cmd.ExecuteJobsCmd in project Activiti by Activiti.

the class ExecuteJobsRunnable method handleSingleJob.

protected void handleSingleJob() {
    final SingleJobExecutorContext jobExecutorContext = new SingleJobExecutorContext();
    final List<JobEntity> currentProcessorJobQueue = jobExecutorContext.getCurrentProcessorJobQueue();
    final CommandExecutor commandExecutor = jobExecutor.getCommandExecutor();
    currentProcessorJobQueue.add(job);
    Context.setJobExecutorContext(jobExecutorContext);
    try {
        while (!currentProcessorJobQueue.isEmpty()) {
            JobEntity currentJob = currentProcessorJobQueue.remove(0);
            try {
                commandExecutor.execute(new ExecuteJobsCmd(currentJob));
            } catch (Throwable e) {
                log.error("exception during job execution: {}", e.getMessage(), e);
            } finally {
                jobExecutor.jobDone(currentJob);
            }
        }
    } finally {
        Context.removeJobExecutorContext();
    }
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ExecuteJobsCmd(org.activiti.engine.impl.cmd.ExecuteJobsCmd)

Example 2 with ExecuteJobsCmd

use of org.activiti.engine.impl.cmd.ExecuteJobsCmd in project Activiti by Activiti.

the class ExecuteJobsRunnable method handleMultipleJobs.

protected void handleMultipleJobs() {
    final MultipleJobsExecutorContext jobExecutorContext = new MultipleJobsExecutorContext();
    final List<String> currentProcessorJobQueue = jobExecutorContext.getCurrentProcessorJobQueue();
    final CommandExecutor commandExecutor = jobExecutor.getCommandExecutor();
    currentProcessorJobQueue.addAll(jobIds);
    Context.setJobExecutorContext(jobExecutorContext);
    try {
        while (!currentProcessorJobQueue.isEmpty()) {
            String currentJobId = currentProcessorJobQueue.remove(0);
            try {
                commandExecutor.execute(new ExecuteJobsCmd(currentJobId));
            } catch (Throwable e) {
                log.error("exception during job execution: {}", e.getMessage(), e);
            } finally {
                jobExecutor.jobDone(currentJobId);
            }
        }
    } finally {
        Context.removeJobExecutorContext();
    }
}
Also used : CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ExecuteJobsCmd(org.activiti.engine.impl.cmd.ExecuteJobsCmd)

Aggregations

ExecuteJobsCmd (org.activiti.engine.impl.cmd.ExecuteJobsCmd)2 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)2 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)1