use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class QueryRunCommand method execute.
public ExecutionResults execute(CommandContext ctx) {
BeanManager manager = CDIUtils.lookUpBeanManager(ctx);
String clazz = QueryService.class.getName();
try {
QueryService cdiBean = (QueryService) CDIUtils.createBean(Class.forName(clazz), manager);
logger.info("CDI bean created {}", cdiBean);
String mapperClass = (String) ctx.getData("mapper");
if (mapperClass == null) {
mapperClass = "org.jbpm.kie.services.impl.query.mapper.ProcessInstanceQueryMapper";
}
Method m = Class.forName(mapperClass).getMethod("get", new Class[0]);
QueryResultMapper<?> mapper = (QueryResultMapper<?>) m.invoke(null, new Object[0]);
Object queryR = cdiBean.query((String) ctx.getData("query"), mapper, new QueryContext());
logger.info("Result of the query is " + queryR);
} 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;
}
use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class ExecutionErrorCleanupCommand method execute.
@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
SimpleDateFormat formatToUse = DATE_FORMAT;
String dataFormat = (String) ctx.getData("DateFormat");
if (dataFormat != null) {
formatToUse = new SimpleDateFormat(dataFormat);
}
ExecutionResults executionResults = new ExecutionResults();
String emfName = (String) ctx.getData("EmfName");
if (emfName == null) {
emfName = "org.jbpm.domain";
}
String singleRun = (String) ctx.getData("SingleRun");
if ("true".equalsIgnoreCase(singleRun)) {
// disable rescheduling
this.nextScheduleTimeAdd = -1;
}
String nextRun = (String) ctx.getData("NextRun");
if (nextRun != null) {
nextScheduleTimeAdd = DateTimeUtils.parseDateAsDuration(nextRun);
}
// get hold of persistence and create instance of audit service
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(emfName);
// collect parameters
String olderThan = (String) ctx.getData("OlderThan");
String olderThanPeriod = (String) ctx.getData("OlderThanPeriod");
String forProcess = (String) ctx.getData("ForProcess");
String forProcessInstance = (String) ctx.getData("ForProcessInstance");
String forDeployment = (String) ctx.getData("ForDeployment");
if (olderThanPeriod != null) {
long olderThanDuration = DateTimeUtils.parseDateAsDuration(olderThanPeriod);
Date olderThanDate = new Date(System.currentTimeMillis() - olderThanDuration);
olderThan = formatToUse.format(olderThanDate);
}
Map<String, Object> parameters = new HashMap<>();
StringBuilder cleanUpErrorsQuery = new StringBuilder();
cleanUpErrorsQuery.append("delete from ExecutionErrorInfo where processInstanceId in " + "(select processInstanceId from ProcessInstanceLog where status in (2,3))");
if (olderThan != null && !olderThan.isEmpty()) {
cleanUpErrorsQuery.append(" and errorDate < :olderThan");
parameters.put("olderThan", formatToUse.parse(olderThan));
}
if (forProcess != null && !forProcess.isEmpty()) {
cleanUpErrorsQuery.append(" and processId = :forProcess");
parameters.put("forProcess", forProcess);
}
if (forProcessInstance != null && !forProcessInstance.isEmpty()) {
cleanUpErrorsQuery.append(" and processInstanceId = :forProcessInstance");
parameters.put("forProcessInstance", Long.parseLong(forProcessInstance));
}
if (forDeployment != null && !forDeployment.isEmpty()) {
cleanUpErrorsQuery.append(" and deploymentId = :forDeployment");
parameters.put("forDeployment", forDeployment);
}
TransactionalCommandService commandService = new TransactionalCommandService(emf);
int deletedErrors = commandService.execute(new UpdateStringCommand(cleanUpErrorsQuery.toString(), parameters));
logger.debug("Number of Execution errors deleted {}", deletedErrors);
executionResults.setData("ErrorsDeleted", deletedErrors);
return executionResults;
}
use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class ReoccurringPrintOutCommand method execute.
public ExecutionResults execute(CommandContext ctx) {
logger.info("Command executed on executor with data {} at {}", ctx.getData(), new Date());
ExecutionResults executionResults = new ExecutionResults();
return executionResults;
}
use of org.kie.api.executor.ExecutionResults 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;
}
use of org.kie.api.executor.ExecutionResults in project jbpm by kiegroup.
the class LongRunningCommand method execute.
public ExecutionResults execute(CommandContext ctx) {
System.out.println(Thread.currentThread().getName() + " [INFO] Command executed on executor with data " + ctx.getData());
long time = 8 * 1000;
System.out.println(Thread.currentThread().getName() + " [INFO] Simulating long running task, sleep time " + time + "ms");
try {
Thread.sleep(time);
} catch (Exception ex) {
}
System.out.println(Thread.currentThread().getName() + " [INFO] Long running task finished after " + time + "ms");
ExecutionResults executionResults = new ExecutionResults();
return executionResults;
}
Aggregations