use of org.kie.kogito.jobs.ProcessInstanceJobDescription in project kogito-runtimes by kiegroup.
the class StateBasedNodeInstance method internalTrigger.
@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getStringId()) == null) {
return;
}
// activate timers
Map<Timer, DroolsAction> timers = getEventBasedNode().getTimers();
if (timers != null) {
addTimerListener();
timerInstances = new ArrayList<>(timers.size());
JobsService jobService = ((KogitoProcessRuntime.Provider) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getKogitoProcessRuntime().getJobsService();
for (Timer timer : timers.keySet()) {
ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new TimerJobId(timer.getId()), createTimerInstance(timer), getProcessInstance().getStringId(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
timerInstances.add(jobService.scheduleProcessInstanceJob(jobDescription));
}
}
if (getEventBasedNode().getBoundaryEvents() != null) {
for (String name : getEventBasedNode().getBoundaryEvents()) {
boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()).isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", name, getProcessInstance().getId());
if (isActive) {
getProcessInstance().getKnowledgeRuntime().signalEvent(name, null);
} else {
addActivationListener();
}
}
}
((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));
}
use of org.kie.kogito.jobs.ProcessInstanceJobDescription in project kogito-runtimes by kiegroup.
the class TimerNodeInstance method internalTrigger.
@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A TimerNode only accepts default incoming connections!");
}
triggerTime = new Date();
ExpirationTime expirationTime = createTimerInstance(getTimerNode().getTimer());
if (getTimerInstances() == null) {
addTimerListener();
}
ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new TimerJobId(getTimerNode().getTimer().getId()), expirationTime, getProcessInstance().getStringId(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
JobsService jobService = InternalProcessRuntime.asKogitoProcessRuntime(getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getJobsService();
timerId = jobService.scheduleProcessInstanceJob(jobDescription);
}
use of org.kie.kogito.jobs.ProcessInstanceJobDescription in project kogito-runtimes by kiegroup.
the class SpringRestJobsServiceTest method testScheduleProcessInstanceJob.
@Test
void testScheduleProcessInstanceJob() {
when(restTemplate.postForEntity(any(URI.class), any(Job.class), eq(String.class))).thenReturn(ResponseEntity.ok().build());
ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(new TimerJobId(123l), ExactExpirationTime.now(), "processInstanceId", "processId");
tested.scheduleProcessInstanceJob(processInstanceJobDescription);
ArgumentCaptor<Job> jobArgumentCaptor = forClass(Job.class);
verify(restTemplate).postForEntity(eq(tested.getJobsServiceUri()), jobArgumentCaptor.capture(), eq(String.class));
Job job = jobArgumentCaptor.getValue();
assertThat(job.getId()).isEqualTo(processInstanceJobDescription.id());
}
use of org.kie.kogito.jobs.ProcessInstanceJobDescription 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));
}
use of org.kie.kogito.jobs.ProcessInstanceJobDescription in project kogito-runtimes by kiegroup.
the class RestJobsServiceTest method testGetCallbackEndpoint.
@Test
void testGetCallbackEndpoint() {
ProcessInstanceJobDescription description = ProcessInstanceJobDescription.of(new TimerJobId(), ExactExpirationTime.now(), "processInstanceId", "processId");
String callbackEndpoint = tested.getCallbackEndpoint(description);
assertThat(callbackEndpoint).isEqualTo("http://localhost:80/management/jobs/processId/instances/processInstanceId/timers/" + description.id());
}
Aggregations