use of org.kie.kogito.services.uow.BaseWorkUnit in project kogito-runtimes by kiegroup.
the class AsyncEventNodeInstance method internalTrigger.
@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
addEventListeners();
addAsyncStatus();
final InternalProcessRuntime processRuntime = (InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime();
// Deffer the timer scheduling to the end of current UnitOfWork execution chain
processRuntime.getUnitOfWorkManager().currentUnitOfWork().intercept(new BaseWorkUnit<>(this, instance -> {
ExpirationTime expirationTime = ExactExpirationTime.of(ZonedDateTime.now().plus(1, ChronoUnit.MILLIS));
ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new AsyncJobId(instance.getStringId()), expirationTime, instance.getProcessInstance().getStringId(), instance.getProcessInstance().getRootProcessInstanceId(), instance.getProcessInstance().getProcessId(), instance.getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
JobsService jobService = processRuntime.getJobsService();
String jobId = jobService.scheduleProcessInstanceJob(jobDescription);
setJobId(jobId);
}, i -> {
}, WorkUnit.LOW_PRIORITY));
}
Aggregations