use of org.jbpm.executor.RequeueAware in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncScriptTaskIgnoreNotExistingDeployments.
@Test(timeout = 1000000)
public void testAsyncScriptTaskIgnoreNotExistingDeployments() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
final NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("Task 1", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncScriptTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new AsyncWorkItemHandler(executorService, PrintOutCommand.class.getName()));
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
listeners.add(countDownListener2);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, "special-test-case");
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
Map<String, Object> params = new HashMap<>();
params.put("delayAsync", "2s");
ProcessInstance processInstance = ksession.startProcess("AsyncScriptTask", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted(1000);
manager.close();
List<RequestInfo> queued = executorService.getQueuedRequests(new QueryContext());
assertNotNull(queued);
assertEquals(1, queued.size());
assertEquals(PrintOutCommand.class.getName(), queued.get(0).getCommandName());
countDownListener2.waitTillCompleted(2000);
queued = executorService.getQueuedRequests(new QueryContext());
assertNotNull(queued);
assertEquals(1, queued.size());
assertEquals(PrintOutCommand.class.getName(), queued.get(0).getCommandName());
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, "special-test-case");
assertNotNull(manager);
runtime = manager.getRuntimeEngine(EmptyContext.get());
countDownListener2.reset(1);
((RequeueAware) executorService).requeueById(queued.get(0).getId());
countDownListener2.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
assertNull(processInstance);
List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
assertNotNull(logs);
assertEquals(8, logs.size());
}
use of org.jbpm.executor.RequeueAware in project jbpm by kiegroup.
the class RequeueRunningJobsCommand method execute.
public ExecutionResults execute(CommandContext ctx) {
Long olderThan = (Long) ctx.getData("MaxRunningTime");
Long requestId = (Long) ctx.getData("RequestId");
try {
ExecutorService executorService = ExecutorServiceFactory.newExecutorService(null);
if (executorService instanceof RequeueAware) {
if (requestId != null) {
logger.info("Requeue jobs by id {}", requestId);
((RequeueAware) executorService).requeueById(requestId);
} else {
logger.info("Requeue jobs older than {}", olderThan);
((RequeueAware) executorService).requeue(olderThan);
}
} else {
logger.info("Executor Service is not capable of jobs requeue");
}
} catch (Exception e) {
logger.error("Error while creating CDI bean from jbpm executor", e);
}
logger.info("Command executed on executor with data {}", ctx.getData());
ExecutionResults executionResults = new ExecutionResults();
return executionResults;
}
Aggregations